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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 984 views
  • 0 likes
  • 4 in conversation