LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (January 2010, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 25 Jan 2010 12:30:28 -0600
Reply-To:     "Data _null_;" <iebupdte@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Data _null_;" <iebupdte@GMAIL.COM>
Subject:      Re: macro- dataset naming
Comments: To: "Mark S." <marksmolkin@gmail.com>
In-Reply-To:  <201001251502.o0PBl8K4019763@malibu.cc.uga.edu>
Content-Type: text/plain; charset=ISO-8859-1

Using the DATAn naming convention would insure that there is never a name conflict because you leave the details of naming to SAS.

Say you are writing a macro that creates two data sets you get the DATAn names from SAS and save these names in macro variables. Then use the macro variables in the program where you would normally use a data set name. If a step has just one output data set you can capture the name with &SYSLAST as soon as the step is done.

If there are two or more outputs from the same step you need to create the names before the multi-output proc or data step and use them as in the following example.

%macro main(data=sashelp.class,by=sex); /* create macro variables for mult-output proc step and populate with DATAn names */ %local outest output; data _data_; stop; run; %let outest = &syslast; data _data_; stop; run; %let output = &syslast;

/* create sorted working data and save name to WORKING */ %local working; proc sort data=&data out=_data_; by &by; run; %let working=&syslast;

/* use the DATAn names for output from proc reg */ proc reg data=&working outest=&outest noprint; by sex; model weight=height; output out=&output r=r p=p; run; quit; /* something useful happend here */

/* tidy up */ proc delete data=&outest &output &working; run;

%mend main;

options mprint=1; %main() options mprint=0;

On 1/25/10, Mark S. <marksmolkin@gmail.com> wrote: > When I write a macro that will contain one or more datasteps (say, for > intermediate calculations) I am never sure how to name them so they do not > interfer with existing datasets. I feel like with larger macros, and > increasing numbers of datasets, I am just asking for trouble. Is there a > way to create datasets 'local' to the macro like can be done with macro > variables? If not, I'd be interested what others do in this situation. > > Mark >


Back to: Top of message | Previous page | Main SAS-L page