BookmarkSubscribeRSS Feed
pkopersk
Fluorite | Level 6

Hello,

I have a user defined macro variable as follows:

%let dfinactg='31jul2018'd;

 

 

data suivi;

set suivi;

attrib rundate format=ddmmyy10.;

rundate=%str(&dfinactg);

runyear=%sysfunc(year("&sysdate9"d));

run;

 

I want to reinsert this variable in the output dataset so I can refer to it in an excel file.

The issue is that the value gets interpreted as a date and when I concatenate it with text like this ="Situation: " & 'Raw Data'!$S$2 &" Broker" (where 'Raw Data'!$S$2 refers to a cell containing the value 07/31/2018 it converts this value to a datenumber.

To resolve this issue, I want to put a single apostrophe like this '07/31/2018 so excel is forced to interpret it as a string.

I haven't succeeded to do so in SAS

Best

2 REPLIES 2
Reeza
Super User
Instead, you can use TEXT function within Excel and convert the value to a date. This way you can change the format easily within Excel if needed as well. That would be my suggestion. There are a lot of benefits to having a date formatted as date.
mkeintz
PROC Star

I often use date literal expressions as macrovars, but don't include the quotes (whether double or single) in the value assigned to the macrovar.  Instead

 

%let dfinactg=31jul2018;

 

Then you can

 

data suivi;

  set suivi;

  attrib rundate format=ddmmyy10.;

  rundate="&dfinactg"d;

  runyear=%sysfunc(year("&sysdate9"d));

run;

 

 

In other words, construct the user-defined macrovar dfinactg the same as the system defines variable sydate9.

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1614 views
  • 1 like
  • 3 in conversation