BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear ,

 By using the following code I need output for AESERN variable for observations 3 and 4 as Yes (1) and Yes (1,2). But my output is without space between the 'YES' and parenthesis. Please help in my code.

 

My output=Yes(1) and Yes(1,2)

 

data one;
input AESER $ AESDTH $ AESLIFE $ AESHOSP $ AESCONG $ AESDISAB $ AESMIE $ INFECDIS $;
datalines;
N N N N N N N N
Y N N N N N N N
Y Y N N N N N N
Y Y Y N N N N N
;
run;

data TWO;
length AESERN $20;
set one;
array AESP {7} $ AESDTH -- INFECDIS;
array POS {7} $1 ;
drop I POS:;
AESERN =ifc( AESER = 'N' , 'No', 'Yes');
if AESERN = 'Yes' and whichc('Y', of AESP[*]) then do;
do I = 1 to 7;
if AESP[I]='Y' then POS[I]=cat(I);
end;
AESERN = cats(AESERN, '(', catx(',', of POS[*]), ')');
end;
run;

3 REPLIES 3
Cynthia_sas
SAS Super FREQ
Hi,
I suggest you look up the way that the CATS and CATX functions work. Specificatlly, for CATS, which is your outer function call. CATS will strip both leading and trailing blanks from the string being generated. You might want to investigate other functions. For example, the simple CAT function, which operates differently than CATS.

cynthia
slchen
Lapis Lazuli | Level 10

cats remove leading and trailing blank, catt remove trailing blank. So, try this:

 

AESERN = catt(AESERN, ' (', catx(',', of POS[*]), ')');

knveraraju91
Barite | Level 11

Thank you very much

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
  • 1603 views
  • 2 likes
  • 3 in conversation