Date: Tue, 1 Aug 2006 17:30:21 -0700
Reply-To: SAS LEARNER1 <kappel_chris@YAHOO.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: SAS LEARNER1 <kappel_chris@YAHOO.COM>
Organization: http://groups.google.com
Subject: Re: Hi all!!
In-Reply-To: <44cfedac$0$22359$afc38c87@news.optusnet.com.au>
Content-Type: text/plain; charset="iso-8859-1"
Hi Scott,
Thanks a lot for the solution. I sincerely appreciate your help! I
tried doing this using the macros and came up with this solution.
Wanted to cross verify from you. I was told to do this using 'macros'
only.
data mac;
input state $ index subcat id;
datalines;
MN 5 1 40
MN 5 2 30
MN 5 3 35
ID 6 1 44
ID 6 2 34
CO 7 3 33
CO 7 5 32
AL 9 1 48
AL 9 5 55
AL 9 3 22
ME 8 2 44
ME 8 1 33
;
%let hdx=mac;
data mac;
set &hdx;
if index>8;
run;
proc print noobs;
title 'Records with highest index';
run;
Regards,
chris
Scott Bass wrote:
> Hi SAS Learner,
>
> Part of macro expertise is knowing when *not* to use macro. You don't need
> it for your example.
>
> Here is but one of about 7 approaches :-)
>
> data test;
> input State $ index subcat id;
> cards;
> MN 5 1 40
> MN 5 2 30
> MN 5 3 35
> ID 6 1 44
> ID 6 2 34
> CO 7 3 33
> CO 7 5 32
> AL 9 1 48
> AL 9 5 55
> AL 9 3 22
> ME 8 2 44
> ME 8 1 33
> ;
> run;
>
> proc sql noprint;
> create table test2 as
> select *
> from test
> where index =
> (select max(index) from test)
> ;
> quit;
>
> data test3;
> set test2;
> if index > 8;
> run;
>
> You could perhaps use a case statement in the SQL code to accomplish
> everything in one pass, but you didn't say what should happen if index is
> never > 8. Should the dataset be empty?
>
> If you're not comfortable with SQL (try to learn it, it really is a useful
> procedure), then here is another approach:
>
> proc summary data=test;
> output out=max max(index)=max;
> run;
>
> data test2 (drop=max);
> if _n_=1 then set max (keep=max);
> set test;
> if index = max and max > 8;
> run;
>
> Lastly, if you could post self-contained, ready-to-cut-and-paste-into-SAS
> code examples, using the cards or datalines statements (as I've done above),
> that would help others in the group help you.
>
> HTH,
> Scott
>
> <kappel_chris@yahoo.com> wrote in message
> news:1154446347.972888.282290@m73g2000cwd.googlegroups.com...
> > Hi!
> >
> > I am new to this group. I have a querry to ask in SAS. The problem is
> > as follows:-
> >
> > State index subcat id
> > MN 5 1 40
> > MN 5 2 30
> > MN 5 3 35
> > ID 6 1 44
> > ID 6 2 34
> > CO 7 3 33
> > CO 7 5 32
> > AL 9 1 48
> > AL 9 5 55
> > AL 9 3 22
> > ME 8 2 44
> > ME 8 1 33
> >
> > Ex-1)
> > 1) Read the above data into SAS.
> > 2) If the value of index is greater than 8, save such value in a macro
> > variable called 'hdx'.
> > 3) Create another macro variable and store a value 'highest' in it.
> > 4) Create a new dataset by subsetting the above dataset. The
> > subsettting should use the macro variable 'hdx' (created above) and get
> > the records with highest index. The output of this subsetting will be
> > as follows:
> > AL 9 1 48
> > AL 9 5 55
> > AL 9 3 22
> >
> > Can anyone help me out! I would be highly appreciative. I would like to
> > know the SAS code for part 1, 2, 3 and 4.
> >
> > Thanks in advance.
> > SAS Learner
> >
|