BookmarkSubscribeRSS Feed
ZoeyElle
Calcite | Level 5
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?
4 REPLIES 4
Ksharp
Super User
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]
yonib
SAS Employee
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;
ZoeyElle
Calcite | Level 5
Hi Ksharp and yonib;

Will try out the suggestions. Thank you very much!
Peter_C
Rhodochrosite | Level 12
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

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1000 views
  • 0 likes
  • 4 in conversation