?
Solved

SAS Macro Varible Format

Posted on 2009-05-06
3
Medium Priority
?
1,937 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 200 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

719 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