DATA Step, Macro, Functions and more

SAS date to YYYYMMDD format issue

Accepted Solution Solved
Reply
Contributor
Posts: 41
Accepted Solution

SAS date to YYYYMMDD format issue

My date is date=20361;
I need my date format to be in YYYYMMDD format.
I tried to use this format YMMDDxw. format

 

Piece of code :-

 

data _null_;

tdy_date = put(date, yymmddn8.);
call symput('today_dt', tdy_date);
run;

 

data _null_;
file output_&today_dt.;
set output_ds;
run;


Accepted Solutions
Solution
‎03-23-2018 01:08 PM
Super User
Posts: 22,823

Re: SAS date to YYYYMMDD format issue

Then it'll depend on how you created your macro variable, but issues it the same, you're not passing the date to the function correctly.

 

tdy_date = put(&date, yymmddn8.);

It could be as simple as adding the & in front of your macro variable name.

View solution in original post


All Replies
Super User
Posts: 22,823

Re: SAS date to YYYYMMDD format issue

Unless you have a variable date, this doesn't create anything, but since you don't have a SET statement, you don't have any variables. 

 

 

tdy_date = put(date, yymmddn8.);

Were you intending to use TODAY() to return today's date?

tdy_date = put(today(), yymmddn8.);

@GunnerEP wrote:

My date is date=20361;
I need my date format to be in YYYYMMDD format.
I tried to use this format YMMDDxw. format

 

Piece of code :-

 

data _null_;

tdy_date = put(date, yymmddn8.);
call symput('today_dt', tdy_date);
run;

 

data _null_;
file output_&today_dt.;
set output_ds;
run;


 

Contributor
Posts: 41

Re: SAS date to YYYYMMDD format issue

Yes i do have a variable date passed from script. & its not today literally, the date is read from a file. So it can be date which is like 4 days back as well.

Super User
Posts: 22,823

Re: SAS date to YYYYMMDD format issue

@GunnerEP Where is the date then? In another data set, in a macro variable? Maybe you need to add the SET statement to make the data available.

 

Contributor
Posts: 41

Re: SAS date to YYYYMMDD format issue

Yes macro variable.
Solution
‎03-23-2018 01:08 PM
Super User
Posts: 22,823

Re: SAS date to YYYYMMDD format issue

Then it'll depend on how you created your macro variable, but issues it the same, you're not passing the date to the function correctly.

 

tdy_date = put(&date, yymmddn8.);

It could be as simple as adding the & in front of your macro variable name.

Contributor
Posts: 41

Re: SAS date to YYYYMMDD format issue

Thanks! Yes i missed the & in deed! Smiley Sad
Super User
Posts: 9,551

Re: SAS date to YYYYMMDD format issue

data _null_;
tdy_date = put(date(), yymmddn8.); /* use the function date() here */
call symput('today_dt', tdy_date);
run;

data _null_;
file output_&today_dt.; /* do you have a fileref output_20180323 ? */
/* if not, you probably should use double quotes and a file extension */
set output_ds;
/* without a put statement, nothing will be written to the file */
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 41

Re: SAS date to YYYYMMDD format issue

Posted in reply to KurtBremser
Hi Kurt,

Date is retrieved from a macro variable. To determine the tdy_date.

I do have a file ref, i am getting my output its just that the date variable is not getting resolved in the file name.
& i have put statement as well.( apologies missed out when i copied it here).
Super User
Posts: 9,551

Re: SAS date to YYYYMMDD format issue

Don't force us to make guesses. Post your REAL code. And example data for the dataset from which you retrieve the date.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 41

Re: SAS date to YYYYMMDD format issue

Posted in reply to KurtBremser
Will keep this in mind from next time. Thanks for your response. Good Day!
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 115 views
  • 0 likes
  • 3 in conversation