Solved

SAS Macro Varible Format

Posted on 2009-05-06
3
1,935 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
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…

738 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