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

Hi,

I have the below macro variable which outputs 1202.

%Let yymm = %sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()),-1,end)),yymmn4.));

Now I want to use the above macro variable(&yymm.) and  output ONLY the year in YYYY format(2012).

%Let yyyy = %sysfunc(year(&yymm.));

I tried the above step and it is giving me 1963 as output. Can someone take a look?

Thanks in advance!.

1 ACCEPTED SOLUTION

Accepted Solutions
cbob
Calcite | Level 5

It worked!!!. Thanks Karl..

View solution in original post

3 REPLIES 3
KarlK
Fluorite | Level 6

%let yyyy = %sysfunc(year(%sysfunc(inputn(&yymm,yymmn4.))));

HTH,

Karl

cbob
Calcite | Level 5

It worked!!!. Thanks Karl..

Patrick
Opal | Level 21

Macro var &yymm contains a string like 1209. The year function expects a SAS date value (date expressed as number of days since 1/1/1960).

1209 days is a date in the year 1963.

If you want to use the year function then you née first to convert you string back to a SAS date (using a information - not sure if there is one for your date format).

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