Help using Base SAS procedures

Processing data by group

Reply
Occasional Contributor
Posts: 10

Processing data by group

Sample data (4 variables)

Name Date. Remarks. Cardno
Alfred. 7/2/2011 10:41:22 AM Abcdewer. 321345
Alfred 7/2/2011 11:20:35 AM. Derdfgdsfg.
Alfred 7/2/2011 3:05:22 PM. Fsdcfgvddf
Elsie. 7/2/2011. 2:22:12 PM. Gffggffghh. 456321
Elsie. 7/2/2011. 5:45:21 PM. Sddcffdfgg.


Notice the card no for Albert only appears on the first occurence. Subsequent 2 observations has no card no. I need to ensure that cardno 321345 appears on all 3 observations for Albert. How do go about doing that?
Super User
Posts: 9,681

Re: Processing data by group

Hi.
How about this:



data temp;



infile datalines truncover;



input Name $ Date

&
$50. Remarks $ Cardno ;



datalines;



Alfred 7/2/2011 10:41:22 AM  
Abcdewer.
321345



Alfred 7/2/2011 11:20:35 AM.   Derdfgdsfg.



Alfred 7/2/2011 3:05:22 PM.   Fsdcfgvddf



Elsie 7/2/2011.
2:22:12 PM.   Gffggffghh. 456321



Elsie 7/2/2011.
5:45:21 PM.   Sddcffdfgg.



;



run;



proc sort data=temp;



 by name;



run;



data result;



 merge temp(drop=cardno)
temp(keep=name cardno  where=(cardno
is not missing));



 by name;



run;





[pre]

Ksharp
[/pre]
SAS Employee
Posts: 105

Re: Processing data by group

You can try this:

proc sort data=your_data;
by name;
quit;

data cardno_retain(drop=Cardno rename=(Cardno2=Cardno));
set your_data;
retain Cardno2;
by name;
if first.name then Cardno2=Cardno;
run;
Occasional Contributor
Posts: 10

Re: Processing data by group

Hi Ksharp and yonib;

Will try out the suggestions. Thank you very much!
Valued Guide
Posts: 2,175

Re: Processing data by group

more ..
data temp;
infile datalines truncover;
input Name $ Date & $50. Remarks $ Cardnox ;
* deal with change of Name ;
Lname = lag(name) ;
if not missing(cardnox) then cardno = cardnox ;
else
if name ne Lname then call missing( cardno) ;
else
cardnox = cardno ;
retain cardno lname;
drop cardnox lname ;[pre]
datalines;
Alfred 7/2/2011 10:41:22 AM Abcdewer. 321345
Alfred 7/2/2011 11:20:35 AM. Derdfgdsfg.
Alfred 7/2/2011 3:05:22 PM. Fsdcfgvddf
Elsie 7/2/2011. 2:22:12 PM. Gffggffghh. 456321
Elsie 7/2/2011. 5:45:21 PM. Sddcffdfgg.
Blsie 7/2/2011. 2:22:12 PM. Gffggffghh.
Blsie 7/2/2011. 5:45:21 PM. Sddcffdfgg. 456321
;[/pre]
just one step needed with data is such good order need to ensure display provides two blanks before Remarks
Message was edited by: Peter.C
Ask a Question
Discussion stats
  • 4 replies
  • 128 views
  • 0 likes
  • 4 in conversation