BookmarkSubscribeRSS Feed
srinath3111
Quartz | Level 8

Hi,

I have variables in file like

Name sex dob var1-var4 

 

Here i wanted to merge the multiple records into single record based on the name,dob,gender variables.

 


xx M 22/11/1992 2 0 7 0
xx M 22/11/1992 0 6 0 3
yy F 24/8/1989 2 0 6 0
yy F 24/8/1989 0 9 0 8
zz M 22/11/1992 2 0 7 0
zz M 22/11/1992 0 6 0 3

required

 

xx M 22/11/1992 2 6 7 3

yy F 24/8/1989 2 9 6 8

zz M 22/11/1992 2 6 7 3

Thanks 

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data in the form of a datastep!!

 

You can do this in one proc summary/means step, for example:

proc means data=have;
  by name sex dob;
  var var:;
  output out=want sum=;
run;

Note note tested as I am not here to type test data in.

ballardw
Super User

@srinath3111 wrote:

Hi,

I have variables in file like

Name sex dob var1-var4 

 

Here i wanted to merge the multiple records into single record based on the name,dob,gender variables.

 


xx M 22/11/1992 2 0 7 0
xx M 22/11/1992 0 6 0 3
yy F 24/8/1989 2 0 6 0
yy F 24/8/1989 0 9 0 8
zz M 22/11/1992 2 0 7 0
zz M 22/11/1992 0 6 0 3

required

 

xx M 22/11/1992 2 6 7 3

yy F 24/8/1989 2 9 6 8

zz M 22/11/1992 2 6 7 3

Thanks 


Do you have any records that do not involve 0 in the "standardization" such as?

 

zz M 22/11/1992 2 3 7 8
zz M 22/11/1992 4 6 0 3

If so, what would the result for this look like?

SuryaKiran
Meteorite | Level 14

Check this UPDATE statement:

data have;
infile datalines dlm=' ';
input Name $ sex $ dob ddmmyy10. var1-var4;
Array change _numeric_;
do over change;
if change=0 then change=.;
end;
datalines;
xx M 22/11/1992 2 0 7 0
xx M 22/11/1992 0 6 0 3
yy F 24/8/1989 2 0 6 0
yy F 24/8/1989 0 9 0 8
zz M 22/11/1992 2 0 7 0
zz M 22/11/1992 0 6 0 3
;
run;

proc sort data=have;
by name sex dob;
run;

data want;
update have(obs=0) have;
by name sex dob;
run;
Thanks,
Suryakiran

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 680 views
  • 0 likes
  • 4 in conversation