Hello:
I would like to combine column 'Seq' and 'lab_mom' together. Please advice how to do it. Also, I think there is something wrong with my code cause the column 'lab_child' is not showing the data in SAS. Thanks.
data data3;
infile datalines dlm=',' dsd;
informat ID $4. Seq best8. DOB mmddyy10. lab_mom $8. lab_child $8.;
format dob mmddyys10.;
input ID Seq DOB lab_mom;
datalines;
A045, 1, 05/06/1979, NH,
A045, 2, 05/06/1979, NH,
A045, 1, 05/06/1979, ,NU
B100, 1, 06/15/1982, JJ,
B100, 2, 06/15/1982, JJ,
B100, 1, 06/15/1982, ,PJ
C300, 1, 05/06/1979, KK,
C300, 2, 05/06/1979, KK,
C300, 1, 05/06/1979, ,OL
;
data data3; infile datalines dlm=',' dsd; informat ID $4. Seq best8. DOB mmddyy10. lab_mom $8. lab_child $8.; format dob mmddyys10.; input ID Seq DOB lab_mom; Combined1= cats(seq,lab_mom); combined2= cats(lab_mom,seq); combined3= catx('_',lab_mom,seq); combined4= catx('-',seq,lab_mom); datalines; A045, 1, 05/06/1979, NH, A045, 2, 05/06/1979, NH, A045, 1, 05/06/1979, ,NU B100, 1, 06/15/1982, JJ, B100, 2, 06/15/1982, JJ, B100, 1, 06/15/1982, ,PJ C300, 1, 05/06/1979, KK, C300, 2, 05/06/1979, KK, C300, 1, 05/06/1979, ,OL ; proc print data=data3 noobs; run;
Your result of 1 is when the is no value for lab_mon. NOTE that you have an extra comma in 3 of your data lines statements in the third, sixth and ninth lines. GIGO.
If this combined is supposed to be the lab_child then you should say so.
And saying the code doesn't work without showing what exact code you ran is pretty difficult to tell which code you mean.
Since you do not assign any value to Lab_child why to you expect to see one? there is nothing on the dataline to read for a fifth variable. The variable is in the data set.
HOW do you want Seg and and Lab_mom combined?
some possible ways:
Combined= cats(seq,lab_mom);
combined= cats(lab_mom,seq);
combined= catx('_',lab_mom,seq);
combined= catx('-',seq,lab_mom);
but you really should show what you would expect the combination to look like.
Hi, Ballardw:
The code is not working. The result only show numeric number, such as '1.'. But no charater is appending behind.
So, both Cats and Catx work in the numeric and charateric variables?
@ybz12003 wrote:
So, both Cats and Catx work in the numeric and charateric variables?
Try it. Look at the results and log afterwards, and learn.
See Maxim 4.
Such like,
1NH
2NH
1NU
data data3; infile datalines dlm=',' dsd; informat ID $4. Seq best8. DOB mmddyy10. lab_mom $8. lab_child $8.; format dob mmddyys10.; input ID Seq DOB lab_mom; Combined1= cats(seq,lab_mom); combined2= cats(lab_mom,seq); combined3= catx('_',lab_mom,seq); combined4= catx('-',seq,lab_mom); datalines; A045, 1, 05/06/1979, NH, A045, 2, 05/06/1979, NH, A045, 1, 05/06/1979, ,NU B100, 1, 06/15/1982, JJ, B100, 2, 06/15/1982, JJ, B100, 1, 06/15/1982, ,PJ C300, 1, 05/06/1979, KK, C300, 2, 05/06/1979, KK, C300, 1, 05/06/1979, ,OL ; proc print data=data3 noobs; run;
Your result of 1 is when the is no value for lab_mon. NOTE that you have an extra comma in 3 of your data lines statements in the third, sixth and ninth lines. GIGO.
If this combined is supposed to be the lab_child then you should say so.
And saying the code doesn't work without showing what exact code you ran is pretty difficult to tell which code you mean.
Thank you so much for your great help!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.