BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear,

 

In my data, I need assign a base value to OBS of that subject.

From my data I need to take the value when visit=1 and populate to all subjects.

 

 code:

proc sql;
create table data2 as 
select *,value as base
from data1
where visit=1
group by id;
quit;

 

data1

id        visit               value

1          1                     10

1           2                   20

2           1                   20

2           1                    20

 

output need:

data2

data

id        visit               value              base

1          1                     10                 10

1           2                   20                   10

2           1                   20                    20

2           1                    30                    20

 

2 REPLIES 2
Shmuel
Garnet | Level 18

It is simple and easy to be done by data step:

 

Data data2;

  set data1;

   by id;

        retain base;

        if first.id then base=.;

        if visit=1 then base=value;

run;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post your test data in the form of a datastep in future, I am not here to type in test data for you.  If you need to do this with SQL, then something along the lines of:

select A.*,
         B.VAL as BASE
from   HAVE A
left join (select * from HAVE where VISIT=1) B
on     ...

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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