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;
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
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.
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
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:
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;
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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.