BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SMohanReddy
Obsidian | Level 7

I have a dataset with values

as A,A,B,B,Z,Z,ZC,C,Z,Z

 

The output should be like this A,A,B,B,B,B,B,C,C,C,C

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Data want;

set have;

 

retain new_var;

 

if var ne 'Z' then new_var=var;

 

run;

 

 

View solution in original post

4 REPLIES 4
Reeza
Super User

Explain your logic and problem in significantly more detail. 

SMohanReddy
Obsidian | Level 7

Hi I have  a dataset "Products" which has a variable "Prod". This variable has got values 

A

A
B

Z

Z

C

C

Z

Z

Whenever Z value comes up, like in this case Z has come up 4th observation, so it has to retain preceding value (B) and then again 5th observation is Z, since 4th obs has been replaced the 5th obs has also to be replaced with prior observation. When ever Z pops up it has to take preceding value

so the output is

A

A

B

B

C

C

C

C

Reeza
Super User

Data want;

set have;

 

retain new_var;

 

if var ne 'Z' then new_var=var;

 

run;

 

 

SMohanReddy
Obsidian | Level 7

thanks 

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
  • 4 replies
  • 972 views
  • 1 like
  • 2 in conversation