Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

SAS Macro Varible Format

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Microsoft Jet database engine errors can crop up out of nowhere to disrupt the working of the Exchange server. Decoding why a particular error occurs goes a long way in determining the right solution for it.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

564 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