BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

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

;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User
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.

View solution in original post

7 REPLIES 7
ballardw
Super User

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.

ybz12003
Rhodochrosite | Level 12

Hi, Ballardw:

 

The code is not working.  The result only show numeric number, such as '1.'.   But no charater is appending behind.

ybz12003
Rhodochrosite | Level 12

So, both Cats and Catx work in the numeric and charateric variables?

Kurt_Bremser
Super User

@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.

ybz12003
Rhodochrosite | Level 12

Such like,

1NH

2NH

1NU

ballardw
Super User
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.

ybz12003
Rhodochrosite | Level 12

Thank you so much for your great help!

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
  • 7 replies
  • 38769 views
  • 1 like
  • 3 in conversation