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

Hello all,

 

I'm encountering an irritating problem I was hoping to get some input on.

 

We have a global dates macro in our environment that I'm using to get a list of date variables. I'm using this for another program I'm writing.

 

The date I'm given from our gloal macro is formatted 'MM/DD/YYYY'. The variable &pdeg resolves to '09/23/2015'. I want to rearrange the date so that it's YYYYMMDD.

 

Here is my code:

 

%let date = %sysfunc(
cat(
%qsubstr(&pdeg,8,4),
%qsubstr(&pdeg,2,2),
%qsubstr(&pdeg,5,2)
)
);

 

The problem with this is that  it's giving me the result of 2015923. I'm losing the 0. It's driving me crazy. I know there is a simple solution here but it's evading me. Appreciate any assistance!

1 ACCEPTED SOLUTION

Accepted Solutions
Ody
Quartz | Level 8 Ody
Quartz | Level 8
You know, upon further reflection I suppose there is no harm in leaving it numeric. I had to modify your statement slightly:

%let date = %sysfunc(inputn(%qsubstr(&pdeg,2,10), mmddyy10.), yymmddn8.);

Thanks!

View solution in original post

4 REPLIES 4
ballardw
Super User

Try

%let pdeg=09/23/2015;
%let date = %sysfunc(putn(%sysfunc(inputn(&pdeg,mmddyy10.)),yymmddn8.));
%put &date;
Ody
Quartz | Level 8 Ody
Quartz | Level 8
You know, upon further reflection I suppose there is no harm in leaving it numeric. I had to modify your statement slightly:

%let date = %sysfunc(inputn(%qsubstr(&pdeg,2,10), mmddyy10.), yymmddn8.);

Thanks!
ballardw
Super User

If your PDEG variable was built from something else It might be even easier to use that instead of a string.

Astounding
PROC Star
Why complicate things by adding the CAT function? %let date = %substr(&pdeg,8,4)/%substr(&pdeg,2,2)/%substr(&pdeg,5,2);

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 785 views
  • 1 like
  • 3 in conversation