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

Hi- I have a table with ID, start year month, end year month and sales per month like below:

IDst_yrmoend_yrmosalespermo
a20170120170312.9
b20180120180412.5
c20170520170613.8
c20171020171212.2

 

For each ID for the range, I would like to have a table like below which has ID, month and sales per month for each month as per table above.

IDyrmosalespermo
a20170112.9
a20170212.9
a20170312.9
b20180112.5
b20180212.5
b20180312.5
b20180412.5
c20170513.8
c20170613.8
c20171012.2
c20171112.2
c20171212.2
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data have;
infile cards expandtabs truncover;
input ID $	(st_yrmo	end_yrmo) (:yymmn6.)	salespermo;
format st_yrmo	end_yrmo yymmn6.;
cards;
a	201701	201703	12.9
b	201801	201804	12.5
c	201705	201706	13.8
c	201710	201712	12.2
;
data want;
 set have;
 do while(st_yrmo<=end_yrmo);
  output;
  st_yrmo=intnx('month',st_yrmo,1);
 end;
run;

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Are the dates in your original table character or numeric?

 

If numeric, please indicate if the first value in the first row is the integer 201701 or is it a real SAS date value formatted as YYMM6.

--
Paige Miller
novinosrin
Tourmaline | Level 20
data have;
infile cards expandtabs truncover;
input ID $	(st_yrmo	end_yrmo) (:yymmn6.)	salespermo;
format st_yrmo	end_yrmo yymmn6.;
cards;
a	201701	201703	12.9
b	201801	201804	12.5
c	201705	201706	13.8
c	201710	201712	12.2
;
data want;
 set have;
 do while(st_yrmo<=end_yrmo);
  output;
  st_yrmo=intnx('month',st_yrmo,1);
 end;
run;
AviS
Fluorite | Level 6

Thanks a lot. This worked perfect for my purpose.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 442 views
  • 0 likes
  • 3 in conversation