BookmarkSubscribeRSS Feed
rajeshalwayswel
Pyrite | Level 9


data gd;
input id$ visit sbp dbp;
cards;
001 10 120 90
001 10 110 .
001 10 130 .
001 20 110 90
001 30 110 98
002 10 120 .
002 10 110 80
002 10 130 98
002 20 110 90
002 30 110 98
003 10 120 90
003 10 110 80
003 10 130 98
003 10 110 90
003 20 120 .
003 30 110 98
;
run;

 

For a subject if sys, dbp is missing after first record we need to return first value to it missing value to it next records. If first record is also missing for a subject we need to set to missing.

 

My Code:

 

proc sort data=gd;by id visit;run;

 

data gd4;
set gd;
by id visit;
if first.id;
b=dbp;
run;


data gd6;
merge gd gd4;
by id;
/*if missing(dbp) then dbp=b;*/
/*else b=dbp;*/
/*b=dbp;*/
run;

 

5 REPLIES 5
mkeintz
PROC Star

I find part of your problem description a bit ambiguous.   You said (bold-italics are mine)

 


 

For a subject if sys, dbp is missing after first record we need to return first value to it missing value to it next records. If first record is also missing for a subject we need to set to missing


 

What do you mean by "first record is also missing"?   That it is missing in addition to a later missing obs?   Do you mean if first obs is missing, then all obs should be set to missing?  Please give an example of desired output:

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
rajeshalwayswel
Pyrite | Level 9

Required Output:

data gd;
input id$ visit sbp dbp;
cards;
001 10 120 90
001 10 110 90
001 10 130 90
001 20 110 90
001 30 110 98
002 10 120 .
002 10 110 80
002 10 130 98
002 20 110 90
002 30 110 98
003 10 120 90
003 10 110 80
003 10 130 98
003 10 110 90
003 20 120 90
003 30 110 98
;
run;

Reeza
Super User

Retain Y;

if not missing(dbp) or first.ID then Y=dbp;

 

rajeshalwayswel
Pyrite | Level 9

Thanks Reeza....

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 1212 views
  • 1 like
  • 3 in conversation