Questions tagged [sas-macro]

A metaprogramming language used in the SAS suite to modify normal SAS code at run-time.

SAS Macro language offers more flexibility for programming SAS code. SAS code written with SAS Macro will be compiled before execution. SAS Macro language uses % for calling SAS macro functions and for calling and defining macros, e.g.:

%macro temp;
  %put %sysfunc(date());
%mend;
%temp;

Variables are used with &, e.g.:

%let my_var = "Hello World";
%put &my_var.;

More about

1265 questions
3
votes
1 answer

SAS: Why is the IN operator within a macro not a default?

From Sample 35591, The IN operator can be used in the %IF statement only when the MINOPERATOR option is set in the %MACRO statement or as a SAS® system option. Requiring a separate option for macro processing seems like an unnecessary…
Lorem Ipsum
  • 4,020
  • 4
  • 41
  • 67
3
votes
2 answers

Passing SAS dataset column as macro parameter

I have a SAS dataset with values yyyymm 201605 201606 201607 201608 201609 I am trying to find a way to pass these values one at a time to macro such that do while dataset still has value %macro passdata(yyyymm); end How can I do this in SAS. Can…
Lauren
  • 51
  • 1
  • 5
3
votes
1 answer

how to record the moving direction is SAS?

I have a maze file which is like this. 1111111 1001111 1101101 1101001 1100011 1111111 a format $direction indicating the direction start end label D D down L L left R R right U U up Then, I have a dataset indicating…
Dan
  • 31
  • 2
3
votes
2 answers

How to discover if a SAS option or ODS option is set

I often write general purpose macros in SAS. Within my macro I want to apply some settings, like macro variables SAS options ODS options But afterwards I want to "clean up my mess". For a macro variable that would be %macro myMac(); %let…
Dirk Horsten
  • 3,753
  • 4
  • 20
  • 37
3
votes
3 answers

Get values of Macro Variables in a SAS Table

I have a set of input macro variables in SAS. They are dynamic and generated based on the user selection in a sas stored process. For example:There are 10 input values 1 to 10. The name of the macro variable is VAR_. If a user selects 2,5,7 then 4…
learnlearn10
  • 169
  • 1
  • 3
  • 15
3
votes
3 answers

Does a macro variable created in PROC SQL become local or global

When I write: proc sql; select count(*) into :out from sashelp.cars; quit; Does the macro variable out become a global or local variable?
Victor
  • 16,609
  • 71
  • 229
  • 409
3
votes
4 answers

SAS - Dynamically create column names using the values from another column

I Have a column with many flags that were parsed from a XML parser. Data looks like this: USERKEYED=Y;VALMATCH=N;DEVICEVERIFIED=N;EXCEPTION=N;USERREGISTRD=N;ASSOCIATE=Y;EXTERNAL=N;GROSSGIVEN=Y;UMAPPED=N; I have to create a table with all these…
Naga Vemprala
  • 718
  • 3
  • 16
  • 38
3
votes
1 answer

When to quote a macro variable

In SAS, while referencing a macro variable, I see that sometimes the code uses double quotes around the macro reference, but other times, it reference the variable without the quotes. When should I use quotes before my & and when should I not?
Victor
  • 16,609
  • 71
  • 229
  • 409
3
votes
1 answer

Error Handling in a sas macro

I am writing a simple macro to count distinct values in all the columns of a table. I need to include an error handler which displays an error information and conitnues to execute the macro further, if certain column is found in the first but not…
ch1nmay
  • 81
  • 1
  • 7
3
votes
2 answers

SAS Adding Minutes to a Timestamp Stored in a Macro Variable

I am pulling a large amount of data from an SQL Server through SAS. I would like to pull one minute (or hour) of data at a time, using a loop. The format of the timestamp is 'yyyymmdd hh:mm:ss.000'. Usually, I would do something like: %macro…
milcak
  • 260
  • 1
  • 3
  • 13
3
votes
2 answers

Testing for an empty parameter in a SAS Macro

For example, i have a macro program %macro test(parameter1= , parameter2=, parameter3=); DATA data_gender; SET data_input(WHERE=(gender=parameter3)); RUN; ..... %mend; Basically, i made a selection of observations using the parameter3…
buiquanghai
  • 81
  • 1
  • 6
3
votes
1 answer

How to obtain the date of a most recently created dataset in SAS libname

I am trying to write some code that will look at all the datasets in a libname and bring back the created date of the most recently created file. I have googled this for an entire day and cannot find a way to do this. I know that ATTRN can determine…
Matt_Roberts
  • 444
  • 1
  • 7
  • 15
3
votes
1 answer

Update Excel output using ODS?

I am running a macro program to analyze a data set. In the end of my macro, i used a ODS statement and a proc Report to export my results. What i want is: For each time i run the macro program with a new data set, the results will be updated in a…
buiquanghai
  • 81
  • 1
  • 6
3
votes
4 answers

Getting ERROR :Unable to clear or re-assign the library DATA1 because it is still in use in SAS

Here is the code I'm running and I'm not sure why I'm getting that ERROR. options symbolgen mlogic; libname lib11 '/home/userid'; %macro SFTPLoop(ds); %global numobs; %let dsid = %sysfunc(open(&ds)); %if &dsid %then %do; %let NumObs=…
SAS_learner
  • 521
  • 1
  • 13
  • 30
3
votes
1 answer

SAS: getting the filesize of created DBF file

I have SAS stored process that ceates DBF file from SAS data set rr_udf_value and finds its size (F_SIZE): filename dbfout "/SASInside/DBF/myfile"; proc export data=rr_udf_value outfile=dbfout dbms=dbf replace; run; %let…
PierreVanStulov
  • 425
  • 2
  • 11