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

Hi I have this dataset. The date column is always the last day of the month. 

 

Customer Type DateValue
A31-Aug-18100
B31-Aug-18120
A31-Jul-1880

 

I want this output. I want the value column to repeat for all dates in that month. 

 

Customer Type DateValue
A01-Aug-18100
A02-Aug-18100
A03-Aug-18100
A04-Aug-18100
A05-Aug-18100
B01-Aug-18120
B02-Aug-18120
B03-Aug-18120
B04-Aug-18120
A01-Jul-1880
A02-Jul-1880
A03-Jul-1880
A04-Jul-1880

 

 

Thanks for your help

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Do like this

 

data have;
input Customer_Type $ Date:date9. Value;
format Date date9.;
datalines;
A 31-Aug-18 100
B 31-Aug-18 120
A 31-Jul-18 80
;

data want(drop=dt);
   set have(rename=(Date=dt));
   do dt=intnx('Month', dt, 0, 'b') to dt;
      Date=dt;
      output;
   end;
   format Date date9.;
run;

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Do like this

 

data have;
input Customer_Type $ Date:date9. Value;
format Date date9.;
datalines;
A 31-Aug-18 100
B 31-Aug-18 120
A 31-Jul-18 80
;

data want(drop=dt);
   set have(rename=(Date=dt));
   do dt=intnx('Month', dt, 0, 'b') to dt;
      Date=dt;
      output;
   end;
   format Date date9.;
run;
kz134
Obsidian | Level 7

Thank you. This worked. 

 

I understand the do loop. And I understand we created a new variable called DT. I don't understand why we have date=dt. What does that do?

novinosrin
Tourmaline | Level 20

Hi @kz134 While i fully agree with @PeterClemmensen, the code can be written as 

 

data have;
input Customer_Type $ Date:date9. Value;
format Date date9.;
datalines;
A 31-Aug-18 100
B 31-Aug-18 120
A 31-Jul-18 80
;

data want;
   set have;
   do date=intnx('Month', date, 0, 'b') to date;
      output;
   end;
run;

The idea is to thoroughly understand the compilation process 

data_null__
Jade | Level 19

I would suggest to use INTNX for the stop value too.  Also suggest this great paper on the subject of DOing things.

http://support.sas.com/resources/papers/proceedings13/126-2013.pdf

 

 

data want;
   set have;
   do date=intnx('Month',date,0,'b') to intnx('Month',date,0,'e');
      output;
      end;
   run;

 

 

novinosrin
Tourmaline | Level 20

Great nit. Noted Boss.  Thank you again. Please get used to the phrase "Thank you". 🙂

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1380 views
  • 5 likes
  • 4 in conversation