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

Hi, I am trying to repeat the same value for all similar dates. 

My data looks like this, where first column is month and year and second column is a percentage:

 

month-year      monthly-com

03M2015         0.57

03M2015

03M2015

04M2015        0.63

04M2015

05M2015        0.73

05M2015

05M2015

 

The values of second column should be repeated for all similar month-year. I tried the below code but it does not work. Anybody can help? Thanks!

data outputData (drop=temp_Monthly_com temp_month_year); 
set have;
retain temp_Monthly_com . temp_month_year .; 
if temp_month_year ne month_year then do;
temp_month_year = month_year;
format temp_month_year MMYY.;
temp_Monthly_com = .;
end;

if Monthly_com = . then temp_Monthly_com=Monthly_com; 
else temp_Monthly_com = Monthly_com; 
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

data want;

set have;

 

retain monthly_com_filled;

if not missing(monthly_com) then monthly_com_filled = monthly_com;

run;

 

Replace Old with your old variable name and new with your new variable name. 

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20
data have;
infile cards truncover;
input month_year $     monthly_com;
cards;
03M2015         0.57
03M2015
03M2015
04M2015        0.63
04M2015
05M2015        0.73
05M2015
05M2015
;

data want;
 update have(obs=0) have;
 by  month_year;
 output;
run;
Bright
Obsidian | Level 7

Thanks for quick reply. I run your code but still the same problem. 

Reeza
Super User

data want;

set have;

 

retain monthly_com_filled;

if not missing(monthly_com) then monthly_com_filled = monthly_com;

run;

 

Replace Old with your old variable name and new with your new variable name. 

Bright
Obsidian | Level 7

Thanks a lot!

novinosrin
Tourmaline | Level 20

Not sure where is the discrepancy unless you post the log and the result you are getting. Here is my test and results

data have;
infile cards truncover;
input month_year $     monthly_com;
cards;
03M2015         0.57
03M2015
03M2015
04M2015        0.63
04M2015
05M2015        0.73
05M2015
05M2015
;

data want;
 update have(obs=0) have;
 by  month_year;
 output;
run;

proc print noobs;run;
month_year monthly_com
03M2015 0.57
03M2015 0.57
03M2015 0.57
04M2015 0.63
04M2015 0.63
05M2015 0.73
05M2015 0.73
05M2015 0.73

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1137 views
  • 1 like
  • 3 in conversation