BookmarkSubscribeRSS Feed
UcheOkoro
Lapis Lazuli | Level 10

Hello,

Please, I need help writing the codes to pick out values from an array of variables. So, the variables thirty_pct1-thirty_pct15 are variables showing if the patient had a 30% decrease in lab values from baseline, so 1 if 'yes' and 0 if 'no'; lab_date1-lab_date5 are the corresponding dates when the lab tests were done and pct_chg1-pct_chg5 is the percent change from baseline. I want to create columns showing the first increase and next decrease with the corresponding lab_dates and pct_chg. The patient with ID 223 has two decreases and increases so there will be two columns for date of decrease and two for dates of increase.

Thank you!

 

data WORK.CLASS(label='Student Data');
 input ID$3. thirty_pct1 thirty_pct2 thirty_pct3 thirty_pct4 thirty_pct5 lab_date1 lab_date2 lab_date3 lab_date4 lab_date5 pct_chg1 pct_chg2 pct_chg3 pct_chg4 pct_chg5;
 datalines;
222 0 1 1 0 1 2JAN2022 1FEB2022 4MAR2022 5APR2022 6MAY2022 -24 -31 -35 -19 -32
223 . 1 0 1 0 . 1FEB2022 4MAR2022 5APR2022 6MAY2022 . -31 -28 -33 -25
224 0 . 1 0 0 2JAN2022 . 4MAR2022 5APR2022 6MAY2022 -24 . -35 -19 -32
 ;run;

 

 

6 REPLIES 6
ballardw
Super User

Now show what you expect the output to look like. I am not sure how many variables you actually expect to add. Is it one per increase/decrease (means maximum of 4 variables for increase and 4 for possible decreases) or 

UcheOkoro
Lapis Lazuli | Level 10

Thank you for your response. I expect the output to look like this:

ID lab_date_of_decrease1  lab_date_of_decrease2  lab_date _of_increase1 labdate _of_increase2 percent_chg1  percent_chg2. The percentage would be for the decrease if there was a decrease or the last increase if there was no decrease.

ballardw
Super User

What if there are more than 2 increases or decreases? Since what I understand of your data is that the values are against a not-shown value at a some other date it seems like you might possibly have more than 2 possible

UcheOkoro
Lapis Lazuli | Level 10
There could be more than 2 or 3 increases and respective decreases the data. The real data has observation with more than 3 increases with respective decreases.
Tom
Super User Tom
Super User

If you want the FIRST how can there be more than one?

Why is your data structured like this?  Why not just make a more normal dataset?

data have ;
  input ID :$3. thirty_pct1-thirty_pct5 (lab_date1-lab_date5) (:date.) pct_chg1-pct_chg5;
  format lab_date1-lab_date5 date9.;
datalines;
222 0 1 1 0 1 2JAN2022 1FEB2022 4MAR2022 5APR2022 6MAY2022 -24 -31 -35 -19 -32
223 . 1 0 1 0 . 1FEB2022 4MAR2022 5APR2022 6MAY2022 . -31 -28 -33 -25
224 0 . 1 0 0 2JAN2022 . 4MAR2022 5APR2022 6MAY2022 -24 . -35 -19 -32
;

data tall ;
  set have;
  array c thirty_pct1-thirty_pct5;
  array d lab_date1-lab_date5;
  array p pct_chg1-pct_chg5;
  do index=1 to dim(d);
    p30 = c[index];
    lab_date = d[index];
    pct_chg = p[index];
    output;
  end;
  format lab_date date9.;
  drop thirty_pct1-thirty_pct5 lab_date1-lab_date5 pct_chg1-pct_chg5;
run;

So you have data like this instead:

Tom_0-1694476140249.png

Now which of those individual records are the ones you want to keep for your new dataset?

Is it something like:

data want;
  set tall;
  where abs(pct_chg) > 30 ;
run;
UcheOkoro
Lapis Lazuli | Level 10

Thank you for your response, Tom. The record I would like to keep are highlighted in yellow. The pattern should be 101010 or 101 or 10 or 1010. It must begin with 1. 

UcheOkoro_0-1694526369552.png

 

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