DATA Step, Macro, Functions and more

Help needed for date formating in Macro

Reply
Occasional Contributor
Posts: 19

Help needed for date formating in Macro

Hi All,

I am having some difficulty to formate date in SAS Macro. I need your help to get this done.

%LET ASATDATE1 = &ASATDATE;

DATA _NULL_;

CALL SYMPUT('LAP_DAT_IND',%sysfunc(inputN(&ASATDATE1,DDMMYY,10)));

%PUT &LAP_DAT_IND;

RUN;

When I ran the code i am getting below error message. Could you please help me on this.

------

 

DATA _NULL_;

CALL SYMPUT('LAP_DAT_IND',%sysfunc(inputN(&ASATDATE1,DDMMYY,10)));

SYMBOLGEN: Macro variable ASATDATE1 resolves to '03-07-2013'

SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing.

250 CALL SYMPUT('LAP_DAT_IND',%sysfunc(inputN(&ASATDATE1,DDMMYY,10)));

_

159

ERROR 159-185: Null parameters for SYMPUT are invalid.

 

WARNING: Argument 1 to function INPUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.

NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The result of the operations have been set

to a missing value.

251 %put &LAP_DAT_IND &ASATDATE;

WARNING: Apparent symbolic reference LAP_DAT_IND not resolved.

SYMBOLGEN: Macro variable ASATDATE resolves to '03-07-2013'

SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing.

&LAP_DAT_IND '03-07-2013'

252 RUN;

 

255 PROC SQL;

256 CREATE TABLE lapse_reg AS

257 SELECT * from people

258 WHERE person_status = '1'

259 and lapse_date < &LAP_DAT_IND;

WARNING: Apparent symbolic reference LAP_DAT_IND not resolved.

259 and lapse_date < &LAP_DAT_IND;

_

22

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,

a missing value, BTRIM, INPUT, PUT, SUBSTRING, USER.

WARNING: Apparent symbolic reference LAP_DAT_IND not resolved.

260 QUIT;

Respected Advisor
Posts: 3,777

Re: Help needed for date formating in Macro

You don't need the data step and CALL SYMPUT just use %let LAP_DAT_IND=%sysfunc(inputN(&ASATDATE1,DDMMYY,10));

Occasional Contributor
Posts: 19

Re: Help needed for date formating in Macro

Hi ,

Thanks for your help on this. I also tried this step but unfortunately it is not working. Please find the logs below.

247        %LET  ASATDATE1 = &ASATDATE;

                                                                                                                                  

248

                                                                                                                                  

249        %LET LAP_DAT_IND2 = %sysfunc(inputN(&ASATDATE1,DDMMYY,10));

                                                                                                                                  

SYMBOLGEN:  Macro variable ASATDATE1 resolves to '03-07-2013'

                                                                                                                                  

SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted for printing.               

                                                                                                                                  

WARNING: Argument 1 to function INPUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.                    

                                                                                                                                  

NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The result of the operations have been set

      to a missing value.

                                                                                                                                  

250

                                                                                                                                  

251        PROC SQL;

                                                                                                                                  

252        CREATE TABLE lapse_reg AS

                                                                                                                                  

253        SELECT * from people

                                                                                                                                  

254        WHERE person_status = '1'

                                                                                                                                  

255        and lapse_date

                                                                                                                                  

SYMBOLGEN:  Macro variable LAP_DAT_IND2 resolves to

                                                                                                                                  

255      ! <

                                                                                                                                  

255      ! &LAP_DAT_IND2;

                                                                                                                                  

           _

                                                                                                                                  

           22

                                                                                                                                  

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,     

                                                                                                                                  

              a missing value, BTRIM, INPUT, PUT, SUBSTRING, USER.

                                                                                                                                  

                                                                                                                                  

                                                                                                                                  

NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements. 

Respected Advisor
Posts: 3,777

Re: Help needed for date formating in Macro

You have quotes around the asatdate they need to be removed.

20         %LET LAP_DAT_IND = %sysfunc(inputN(%sysfunc(dequote(&ASATDATE)),mmddyy,10));
21         %put NOTE: &=asatdate &=lap_dat_ind;
NOTE: ASATDATE='03-06-2013' LAP_DAT_IND=19423
Regular Contributor
Posts: 198

Re: Help needed for date formating in Macro

This page addresses your issues

http://www.sascommunity.org/wiki/Macro_Loops_with_Dates

This section has three ways of getting an integer from a data reference:

http://www.sascommunity.org/wiki/Macro_Loops_with_Dates#A_Date_is_a_Reference_to_an_Integer

Ron Fehd  macro maven

"A SAS date is an index into the associative array of dates."

Ask a Question
Discussion stats
  • 4 replies
  • 981 views
  • 1 like
  • 3 in conversation