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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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