BookmarkSubscribeRSS Feed
Nethra
Calcite | Level 5

Hi,

 

Can someone help me to write the macors for 6 months prior to YYYYMM date in YYMMN format which is already there in Temp dataset as shown below.

 

ID                    Region    YYYYMM

2205500483    3742       201503

1105661211    3411       201410

2010452387    4605       201501

 

data _null_;

call symput('Hist',"'"||put(intnx('month', YYYYMM, -6), YYMMN.)||"'");

run;

%put &Hist.;

 

Proc sql;

Create table Test as

Select id, Region, YYYYMM, &Hist. as Effect_date

from Temp

order by id;

quit;

This step is not working.

7 REPLIES 7
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You appear to be using Macro (a text generation tool) for what should be a datastep process:

data test;
  set temp;
  effect_date=intnx('month',yymm,-6);
  format effect_date yymm6.;
run;
Nethra
Calcite | Level 5
Thanks for the prompt reply!!!

But i get the result in numeric format as 251103, 251012, 251012 even though format is used.

Thanks !!
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Dates and times are numeric.  Dates are number of days since Jan1960 for example.  How you display them is by using the apropriate format, e.g. yymm.  If you need a character varaible - i.e. it is no longer a date - then you use put() function:

data test;
  set temp;
  effect_date=put(intnx('month',yymm,-6),yymm6.);
run;
Nethra
Calcite | Level 5
The output for effect_date is showing as 11M03, 10M12, 11M03....Not getting in YearMonth (201409)
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I would suggest do some reading on formats, a minor change to the format is all that is required, however you should know how to display data using formats, its a key item:

data test;
  yymm="12Aug2011"d;
  effect_date=put(intnx('month',yymm,-6),yymmn6.);
run;
Patrick
Opal | Level 21

@Nethra

Read very carefully everything under this link:

http://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#n0q9ylcaccjgjrn19hvq...

 

It is very important that you fully understand this and it will make your SAS coding life quite a bit easier if you do so,

Nethra
Calcite | Level 5
Thank you all for helping me !!!! The link is useful one.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 7 replies
  • 1235 views
  • 0 likes
  • 3 in conversation