Solved

SAS Macro Varible Format

Posted on 2009-05-06
3
1,927 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
Comment Utility
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
Comment Utility
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
Comment Utility
Awesome work.. Thanks you.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In today’s complex data management environments, it is not unusual for UNIX servers to be dedicated to a particular department, purpose, or database.  As a result, a SAS® data analyst often works with multiple servers, each with its own data storage…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now