BookmarkSubscribeRSS Feed
GeethaMN
Obsidian | Level 7

can anyone answer this query??

there is a input variable called X. need to derive variable called 'Y'.. the scenario is wherever there is 999 value there it has to add 0.1 to the previous x value.. if more than one 999 is there then the order should be 3.1, 3.2,3.3

 

X        Y

1        1
2        2
3        3
4        4
999    4.1
1        1
2        2
3        3
999    3.1
999    3.2

SAAAS
3 REPLIES 3
Reeza
Super User

Use the lag function. 

 

X_lag = lag(X);
Y=ifn(X=999, x_lag+0.1, X);

This doesn't deal with consecutive 999 so you'll need to figure out the logic for that.  

Ksharp
Super User
data have;
input X ;
cards; 
1      
2      
3   
4  
999  
1   
2  
3    
999 
999   
;
run;

data want;
 set have;
 retain Y;
 if X ne 999 then Y=X;
  else Y=Y+0.1;
run;
Ksharp
Super User

Or more simple :

 

 

data want;
 set have;
 if X ne 999 then Y=X;
  else Y+0.1;
run;

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
  • 3 replies
  • 809 views
  • 5 likes
  • 3 in conversation