SAS Macro Varible Format

I have a SAS query fiile with about 50 sequential queries. Some of them use a datetime variable.
When I need to increment that variable, I have to do a find and replace within SAS in order to change it.

I looked at Macro Variables and I feel like i almost have a solution, but I'm missing something.

The code (attached) doesn't work because &datetimestamp contains 01MAY2009:00:00:00dt and not '01MAY2009:00:00:00'dt.

The error is
NOTE: Line generated by the macro variable "DATETIMESTAMP".
1731   01MAY2009:00:00:00dt
        -------
        22
        76


Thanks in advance..
%syslput datetimestamp = sysfunc(datepart('01MAY2009:00:00:00'dt),date9.):00:00:00dt;
 
rsubmit odyssey2;
proc sql;
create table work.dummyData as
	select ticket_number from tickets_DB
	where RESOLVE_TIME_ET >= &datetimestamp;
quit;
endrsubmit;

Open in new window

delta770Asked:
Who is Participating?
 
bradanelsonConnect With a Mentor Commented:
This is more that you asked for, but it's a very good, dynamic way to create MACRO VARIABLES that are the same on your PC and in UNIX.

1) Create as many GlobalVariables as you would like in the DATALINES portion of the GlobalVariables dataset.  I have created 2 as an example below.  DateTimeStamp1 and DateTimeStamp2.

2) Next, it sets each variable as GLOBAL.

3) The DATASTEP here creates diferent iterations of the GlobalVariables you set above.  You can customize the number of iterations you create.  As an example, I create 3 MACRO VARIABLES for each row in the GlobalVariables dataset.  So for DateTimeStamp1, I create 3 GLOBAL VARIABLES; DateTimeStamp with the value unchanged, DateTimeStamp_SQ with the value surrounded with single quotes, and DataTimeStamp_SQ_DT with the value surrounded with single quotes and a DT on the end.

4) Under the RSUBMIT, I upload the GlobalVariables dataset and repeat 2) and 3) in the UNIX enviroment.

5) You can now reference the DateTimeStamp1_SQ_DT GLOBAL VARIABLE in your SQL statement.




DATA GlobalVariables;
    FORMAT GlobalVariable $29. Value $50.;
    INPUT GlobalVariable Value;
    DATALINES;
    DateTimeStamp1       01MAY2009:00:00:00
    DateTimeStamp2       07MAY2009:00:00:00
    ;
RUN;
 
/*SET ALL VARIABLES IN GLOBALVARIABLES DATASET AS GLOBAL ON PC*/
PROC SQL NOPRINT; 
    SELECT GlobalVariable 
    INTO :GlobalVariables 
    SEPARATED BY ' '
    FROM GlobalVariables; 
QUIT;
%GLOBAL &GlobalVariables;
 
/*CREATE GLOBAL VARIABLES FROM GLOBALVARIABLES DATASET ON PC*/
DATA _NULL_;
    SET GlobalVariables;
    CALL SYMPUT(TRIM(GlobalVariable), TRIM(Value));
    CALL SYMPUT(TRIM(GlobalVariable)||'_SQ', "'"||TRIM(Value)||"'");
    CALL SYMPUT(TRIM(GlobalVariable)||'_SQ_DT', "'"||TRIM(Value)||"'DT");
RUN;
 
RSUBMIT odyssey2;
    /*UPLOAD GLOBALVARIABLES DATASET*/
    PROC UPLOAD DATA=GlobalVariables OUT=GlobalVariables; RUN;
 
    /*SET ALL VARIABLES IN GLOBALVARIABLES DATASET AS GLOBAL ON UNIX*/
    PROC SQL NOPRINT; 
        SELECT GlobalVariable 
        INTO :GlobalVariables 
        SEPARATED BY ' '
        FROM GlobalVariables; 
    QUIT;
    %GLOBAL &GlobalVariables;
 
    /*CREATE GLOBAL VARIABLES FROM GLOBALVARIABLES DATASET ON UNIX*/
    DATA _NULL_;
        SET GlobalVariables;
        CALL SYMPUT(TRIM(GlobalVariable), TRIM(Value));
        CALL SYMPUT(TRIM(GlobalVariable)||'_SQ', "'"||TRIM(Value)||"'");
        CALL SYMPUT(TRIM(GlobalVariable)||'_SQ_DT', "'"||TRIM(Value)||"'DT");
    RUN;
ENDRSUBMIT;
 
 
 
 
rsubmit odyssey2;
    proc sql;
    create table work.dummyData as
    	select ticket_number from tickets_DB
    	where RESOLVE_TIME_ET >= &DateTimeStamp1_SQ_DT;
    quit;
ENDRSUBMIT;

Open in new window

0
 
delta770Author Commented:
Wow.. that was incredibly helpful. I removed some of the stuff that I knew I didn't need and it work perfectly.
Thanks a lot for your help and quick response.
0
 
delta770Author Commented:
Awesome work.. Thanks you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.