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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 568 views
  • 0 likes
  • 2 in conversation