Solved

SAS Macro Varible Format

Posted on 2009-05-06
3
1,932 Views
Last Modified: 2013-11-16
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

0
Comment
Question by:delta770
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
bradanelson earned 50 total points
ID: 24317011
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
 

Author Comment

by:delta770
ID: 24374708
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
 

Author Closing Comment

by:delta770
ID: 31578538
Awesome work.. Thanks you.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Read about achieving the basic levels of HRIS security in the workplace.
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question