BookmarkSubscribeRSS Feed
carl_miles
Fluorite | Level 6

data MyDataset;

input id $4. 1L_flag $4. 2L_flag $4.;

datalines;

1 1L 0 

2 1L 2L

3 1L 0

4 1L 2L

5 1L 2L

;

run;

 

I want an output like 

id 1L_flag 2L_flag  1l_2l_flag

1       1L          0            1L

2      1L         2L           1L

2      1L         2L           2L

3      1L         0             1L

4     1L         2L           1L

4     1L         2L           2L

5      1L         2L           1L

5      1L         2L           2L


As we can see in the ouptut the flag made the patient level table to record level by flagging 
So If patients had 1l Only flag will give only 1L
if they 1L & 2L as well then they will have 2 records in the same flags 

[Note: In dataset I have multiple 1l and 2l and 3l .... flags 
and other columns as well with 25 columns

16, 456 rows ]

 

Could guys help to code and how can we do it?

2 REPLIES 2
andreas_lds
Jade | Level 19

Are the other columns expected to appear in the output? I don't think it is a good idea to name the last variable "1l_2l_flag" if the data has more flag-variables. You may want to post data that is closer to the data you have actually.  And please fix the names of your variables so that match the v7 rules - names start with a letter or with an underscore.

 

EDIT: and please re-check the code, it doesn't work as expected due to formatted input.

andreas_lds
Jade | Level 19

I have renamed the flag-variables, if you insist on using bad names, you will have to edit the array statement.

data work.have;
   input id $ flag_L1 $ flag_L2 $;
   datalines;
1 1L 0 
2 1L 2L
3 1L 0
4 1L 2L
5 1L 2L
;

data want;
   set have;

   length flag $ 4;
   array flags flag_L:;

   do i = 1 to dim(flags);
      if flags[i] ^= '0' then do;
         flag = flags[i];
         output;
      end;
   end;

   drop i;
run;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 323 views
  • 0 likes
  • 2 in conversation