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

Hi

 

I would like to repeat a value in varaible across all the observations.

 

For ex:

 

Have:

Obs       Product        Amount         Count

1.           Apple            10.0              8

2.           Pineapple            

3.           Strawberry

4.           Kiwi

5.           Cantaloupe     

 

Want:

Obs      Product        Amount            Count

1.          Apple            10.0                  8

2.          Pineapple     10.0                  8

3.          Strawberry    10.0                  8

4.          Kiwi               10.0                  8

5.          Cantaloupe   10.0                  8 

 

Thanks in advance.

 

Neal

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Is it always the first observation? Is this an existing dataset or does it get created this way somehow.

You can google LOCF (Last observation carried forward)

View solution in original post

4 REPLIES 4
Reeza
Super User
Is it always the first observation? Is this an existing dataset or does it get created this way somehow.

You can google LOCF (Last observation carried forward)
ballardw
Super User

Also, does that variable somewhere in the data reset to a new value? Do both always change together or may the Amount reset separately from the count?

Astounding
PROC Star

If there is really only a value on the first observation, you can do it this way:

 

data want;

if _n_=1 then set have (keep=amount count);

set have (drop=amount count);

run;

 

If there might be additional observations later in the data set that contain AMOUNT and COUNT then you have to go with the LOCF suggestion.  It's not all that complicated.

 

Good luck.

MadhuKorni
Quartz | Level 8

data want(drop = amount count rename = (amount1=amount count1=count));
set have;
retain amount1 count1;
if Amount ne . then amount1=amount ;
if count ne . then count1=count;
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
  • 4 replies
  • 889 views
  • 0 likes
  • 5 in conversation