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.
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 |
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.
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.
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 |
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: