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

Hi ,

         I need to create baseline values: The dataset I have as follows:

subjid         paramcd     visit           aval

001              dbp            1               72

001              dbp           2                 60

001              dbp           3                 78

001              dbp          4                   80

 

The desired dataset:

subjid         paramcd     visit           aval        base

001              dbp            1               72          72

001              dbp           2                 60         72

001              dbp           3                 78         72

001              dbp          4                   80        72

 

if aval=72 is the baseline.

Thanks.

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @rashmirao99  Here is a test-->

 


data have;
input subjid  $       paramcd   $  visit           aval;
cards;
001              dbp            1               72
001              dbp           2                 60
001              dbp           3                 78
001              dbp          4                   80
001              hr             1                   45
001              hr             2                   55
001              hr             3                   60
;

data want;
 set have;
 by subjid paramcd;
 retain base;
 if first.paramcd then base =aval;
run;
subjid paramcd visit aval base
001 dbp 1 72 72
001 dbp 2 60 72
001 dbp 3 78 72
001 dbp 4 80 72
001 hr 1 45 45
001 hr 2 55 45
001 hr 3 60 45

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20
data have;
input subjid  $       paramcd   $  visit           aval;
cards;
001              dbp            1               72
001              dbp           2                 60
001              dbp           3                 78
001              dbp          4                   80
;

data want;
 set have;
 by subjid;
 retain base;
 if first.subjid then base =aval;
run;

Hi @rashmirao99  The idea is 

1. You need to assign the first observation of a by group i.e each subjid to a new variable called base

2. Retain the value of base once assigned across iterations within each subjid by group, otherwise the value of base is reinitialized to missing for each iteration of the datastep. 

rashmirao99
Fluorite | Level 6

No. That doesn't work.  It only populates for the first record.

 

What I want is suppose I have something like this:

 

001              dbp            1               72
001              dbp           2                 60
001              dbp           3                 78
001              dbp          4                   80

001              hr             1                   45

001              hr             2                   55

001              hr             3                   60

 

and The output data I'm expecting is this:

subjid         test            visit          aval        base

001              dbp            1               72          72
001              dbp           2                 60         72
001              dbp           3                 78         72
001              dbp          4                   80        72

001              hr             1                   45       45

001              hr             2                   55       45

001              hr             3                   60       45.

 

 Thanks.

 

 

novinosrin
Tourmaline | Level 20

Hi @rashmirao99  Here is a test-->

 


data have;
input subjid  $       paramcd   $  visit           aval;
cards;
001              dbp            1               72
001              dbp           2                 60
001              dbp           3                 78
001              dbp          4                   80
001              hr             1                   45
001              hr             2                   55
001              hr             3                   60
;

data want;
 set have;
 by subjid paramcd;
 retain base;
 if first.paramcd then base =aval;
run;
subjid paramcd visit aval base
001 dbp 1 72 72
001 dbp 2 60 72
001 dbp 3 78 72
001 dbp 4 80 72
001 hr 1 45 45
001 hr 2 55 45
001 hr 3 60 45

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