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: assign a quantile to a macro variable

In SAS, how can I assign the 97.5% quantile of the normal distribution to the macro variable z? Not working 1 %let z = quantile("normal", 0.975); Not working 2 %let z = %sysfunc(quantile("normal", 0.975));
user7064
  • 217
  • 2
  • 8
3
votes
2 answers

SAS: Creating Tables Dynamically for different dates and table names in one go

I'm stuck to something about creating tables dynamically by date filter. I have SAS code for setting date filters before running main codes. This it the date code; data _null_; /*ACTUAL…
3
votes
2 answers

SAS how to use a macro variable as a date

I have a global macro variable from another macro which looks like '01jan2014' when you print it in the log i.e. there are enforced quotemarks I want to use this in a proc sql statement but I can't as it doesn't like the variable type. How do I…
shecode
  • 1,716
  • 6
  • 32
  • 50
3
votes
3 answers

How do I work out the data type of my macro variable in SAS

How do I print out the data type of a macro variable in the log %macro mymacro(dt2); %LET c_mth = %SYSFUNC(intnx(month,&dt2.d,-1,e),date9.) ; %put &c_mth; %mend; mymacro('01sep2014') I have a bunch of macro variables assigned using a…
shecode
  • 1,716
  • 6
  • 32
  • 50
3
votes
1 answer

SAS ODS escape character macro variable error

The SAS v9.4 documentation lists an automatic macro variable &sysodsescapechar which contains the current ODS escape character, assigned using ods escapechar=. Whenever I try to view the macro variable using a %put statement, I get the following…
Alex A.
  • 5,466
  • 4
  • 26
  • 56
3
votes
2 answers

Implementing recursive bisection in SAS

First question here. Basically, I want to implement a recursive bisection algorithm in SAS via the use of macros. I have already written a macro that takes two arguments (the lower and upper endpoints of the current interval) and produces a table…
heropup
  • 133
  • 3
3
votes
1 answer

Macro sas difference between %str and %bquote

Sample Code :- %Let a = begin; %let b1 = %str(&a); %let b2 = %nrstr(&a); %let b3 = %bquote(&a); %let b4 = %nrbquote(&a); %let b = end; Actual Output :- b1 = begin b2 = &a b3 = begin b4 = begin Expected Output :- b3 = end b4 = &a Is…
Rohit Gupta
  • 31
  • 1
  • 1
  • 2
3
votes
2 answers

Make a SAS data column into a Macro variable?

How can I convert the output of a SAS data column into a macro variable? For example: Var1 | Var2 ----------- A | 1 B | 2 C | 3 D | 4 E | 5 What if I want a macro variable containing all of the values in Var1 to use in a PROC…
vdiddy
  • 85
  • 1
  • 9
3
votes
2 answers

Using a vector generated in SAS/IML as a macro variable

I am writing a macro that will run PROC MIXED with the level-1 residual variance fixed to a near-zero value using the PARMS statement. I am trying to generate the bulk of the starting values for the PARMS statement using SAS/IML, something…
John
  • 33
  • 3
3
votes
4 answers

Convert string with spaces to valid table name

I want to create a series of tables using SAS macro language, but the strings I am trying to pass through have spaces in them. Any ideas on what to add to make them valid table names? %macro has_spaces(string); proc sql; create table &string. as…
CaptainBear
  • 167
  • 3
  • 12
3
votes
1 answer

SAS Macro, passing value as string to where clause

I have a SAS macro below that is not working--- this snippet returns no values because the where statement doesn't work. Anyone have any ideas? I tried adding %str but that didn't work either. %macro refreshments(beverage_type=); proc…
CaptainBear
  • 167
  • 3
  • 12
3
votes
2 answers

Macro escape string

I'm trying to print a line to the console which should print one macro variable and one piece of text with an ampersand in it. Let me illustrate this with a small example: %LET THIS_IS_A_MACRO_VAR = test; %PUT…
3
votes
1 answer

sas string converting in code

I'm trying to use SAS 9.4 data hash obj. Some code here: data joined; if 0 then set data1 data2; if _n_=1 then do; declare hash merger (dataset:'data2'); merger.definekey('some_key'); …
renardeinside
  • 377
  • 1
  • 9
3
votes
2 answers

Position of a word/var in a list SAS

This might be a rather simple question but I am new to SAS and am clueless even after researching on this in Google. I have a macro variable as - %let list = 12AUG2013 13AUG2013 15AUG2013 16AUG2014 09SEPT2014; I need to get the following things…
RHelp
  • 815
  • 2
  • 8
  • 23
3
votes
2 answers

Remove duplicate in SAS similar like ROW_NUMBER () function in Oracle

I am using SCOTT schema in oracle and want to delete the duplicate values like this... SELECT EMPNO, JOB, SAL FROM ( SELECT EMPNO, JOB, SAL, ROW_NUMBER () OVER (PARTITION BY…
goldenbutter
  • 575
  • 2
  • 12
  • 25