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
0
votes
1 answer

SAS Macro Language

On SAS, after defining Macro Language, for example, %macro source(x); ...... %mend source; I want to substitute x for 17 to 63, does there have an easy way to do this instead of key in %source(16); %source(17); ... %source(63);
huadaixia
  • 109
  • 1
  • 6
0
votes
1 answer

Date function in SAS LOOP

I have a date function in EIS column (EX:05FEB2007), I want to loop the year from 31DEC2012 to 31DEC2022, but have to do like 31DEC2012-EIS up to 31DEC2022-EIS in a loop. %MACRO NFORE; %LET UC=100; %LET YS=2012; %DO I = 0 %TO 10; …
Kavitha
  • 371
  • 6
  • 19
0
votes
1 answer

SAS Macro variable to represent what is in an IN statement in Proc SQL

I have a query I want to run through SAS in Proc SQL where I am getting data from one of our company databases. At the top of the query, for ease of use mostly, I want to be able to put a list of input variables. I am interested in getting data…
GeoffDS
  • 1,221
  • 5
  • 19
  • 31
0
votes
2 answers

Optimize building a SAS table with macros

I have a SAS program that dynamically builds a table with a macro like so: %macro Projection; %do i=1 %to &number_of_Years; %Advance_Years; proc sql; create table Projection as select *, Year_&previous_year.*(1+return) as…
Pane
  • 555
  • 2
  • 7
  • 20
0
votes
1 answer

SAS/SAS Macro - Reading observation line by Line

Sample data: PatID Strata1 Strata2 Allocated TG 1 1 1 T1 2 1 2 T2 3 2 3 T1 4 1 3 . 5 2 2 . 6 1 …
0
votes
1 answer

SAS Macro if then else

I am new to SAS and want to make a macro procedure that creates y-axis values for a later PROC GPLOT. In plain English, there are two posssible minimum values (and maxs) on this graph. The axis range is dependent on which minimum value is the…
0
votes
1 answer

Error surrounding use of scan(&varlist) + Comparison of macro variables

As a follow up to this question, for which my existing answer appears to be best: Extracting sub-data from a SAS dataset & applying to a different dataset Given a dataset dsn_in, I currently have a set of macro variables max_1 - max_N that contain…
alexwhitworth
  • 4,839
  • 5
  • 32
  • 59
0
votes
1 answer

Extracting sub-data from a SAS dataset & applying to a different dataset

I have written a macro to use proc univariate to calculate custom quantiles for variables in a dataset (say dsn1) %cust_quants(dsn= , varlist= , quant_list= ). The output is a summary dataset (say dsn2)that looks something like the following: q_1 …
alexwhitworth
  • 4,839
  • 5
  • 32
  • 59
0
votes
1 answer

Retrieving SAS macro from a catalog

Can anyone provide the syntax for retrieving a SAS Macro from a permanent catalog? (ie copy it into my work.sasmacr location) I don't need this as part of my autocall as I won't always be connecting to this library...
Allan Bowe
  • 12,306
  • 19
  • 75
  • 124
0
votes
1 answer

Need a SAS macro program to avoid repetition

I have a dataset where some SAS Datastep logic are needed to populate the columns that are missing, or to be derived from exiting columns. The dataset looks more like the below: mpi v1 v2 v3......v9 v10 v11.....v50 001 a …
Dapsy
  • 1
  • 3
0
votes
1 answer

How to compare date values in a macro?

Here is the macro I'm running.... %macro ControlLoop(ds); %global dset nvars nobs; %let dset=&ds; /* Open data set passed as the macro parameter */ %let dsid = %sysfunc(open(&dset)); /* If the…
SAS_learner
  • 521
  • 1
  • 13
  • 30
0
votes
3 answers

How can I perform a macro for each observation in sas data set?

Here is the macro code..... libname myfmt "&FBRMrootPath./Formats"; %macro CreateFormat(DSN,Label,Start,fmtname,type); options mprint mlogic symbolgen; %If &type='n' %then %do; proc sort data=&DSN out=Out; by &Label; Run; Data ctrl; …
SAS_learner
  • 521
  • 1
  • 13
  • 30
0
votes
1 answer

Trying to create a macro with If-Then conditions in SAS

Here is the code I'm using to creat a format..... libname myfmt "&FBRMrootPath./Formats"; %macro Create_Macro(DSN,Label,Start,fmtname,type); options mprint mlogic symbolgen; %If &type='n' %then %do; proc sort data=&DSN out=Out; by &Label;run; …
SAS_learner
  • 521
  • 1
  • 13
  • 30
0
votes
3 answers

How to repeatedly invoke a SAS macro where the second param is the first with - and . removed?

I have a macro that needs two parameters -- a string that can contain dashes and periods, and a cleaned-up version of the same string where any dashes and periods are replaced by underscores. The following works: %let foo =…
bokov
  • 3,444
  • 2
  • 31
  • 49
0
votes
1 answer

In SAS 9.2, How do I clear a a URL fileref?

I wrote a SAS macro kind of like this... %macro (myname=,myurl=); filename myfile URL "&myurl"; data &myname; infile myfile dlm=','; input field1 field2; run; %mend; It works once, but Whenever I run it again, I get log messages…
bokov
  • 3,444
  • 2
  • 31
  • 49