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 : Concatenate single quote with a value returned from %BQUOTE in a where clause

I am retrieving a few records from PROC SQL using a where clause like this: where mailing_phone_numbers in (%bquote(&phone_numbers.)); But the macro variable phone_numbers does not have a initial "'" single quotation mark and it is creating…
Naga Vemprala
  • 718
  • 3
  • 16
  • 38
0
votes
2 answers

Build macro Variables on another macro var

I would like to "shortcut" this function of a macro variable intnx('YEAR',"&starting_year"D,-5,'S'); with another macro variable. Is it possible ? something like: %let start = intnx('YEAR',"&starting_year"D,-5,'S'); Of course this code-line…
arj
  • 713
  • 2
  • 12
  • 26
0
votes
3 answers

Why proc does not need a % symbol when written inside a SAS macro

I have a basic question about SAS macro. Inside sas macro, when you write a let statement or a put statement or an if statement, you always prefix it with %. But when you write a 'proc' inside a macro, why don't we need to write %proc? Or for…
Victor
  • 16,609
  • 71
  • 229
  • 409
0
votes
3 answers

How to i use %include to invoke a SAS macro

If I write a test.sas with the contents: %macro test; %put test macro; %mend; %test; And then just execute this at a sas session: %include test.sas Will it just invoke the macro 'test'? Or will it just include the macro definition but skip the…
Victor
  • 16,609
  • 71
  • 229
  • 409
0
votes
2 answers

How to use %scan to split the strings that contain dot?

I have a SAS macro string defined as: %let datasets = lib.d1 lib.d2 lib.d3 ; The string is a macro variable. Each element is a dataset with the library name. The elements are separated by line breaks. Now I want to split the elements and iterate…
Steve
  • 4,935
  • 11
  • 56
  • 83
0
votes
1 answer

Can't get this SAS macro right, need advice

Here is the macro below, along with an example at the bottom. When I try to run this I get many errors, and I think it has something to do with the way I am using if-else statements. The example should return "Gum and Other Mouth". Thanks! …
Stu
  • 1,543
  • 3
  • 17
  • 31
0
votes
0 answers

How to access variable of variable inside sysevalf. Character operand was found, expecting numeric operand?

I have a macro variable named bal_Sheet having certain column names which contain numeric values under them. %let bal_Sheet = a1 a2 a3 a4; I am trying to access this variables in the sysevalf function like data abc.xyz; set abc.hfg; keep…
godimedia
  • 987
  • 2
  • 12
  • 28
0
votes
1 answer

Conditionally delete the most recently inserted observation in SAS

I have two tables A and B that look like below. Table A rowno flag1 flag2 flag3 1 1 0 0 2 0 1 1 3 0 0 0 4 0 1 1 5 0 0 1 6 0 …
dozel
  • 127
  • 1
  • 3
  • 9
0
votes
2 answers

When to use double quotes while referencing a SAS macro variable

While referencing a SAS macro variable, when do I need to enclose it in double quotes and when should I not? i.e When to use "&var_name" and when to use &var_name
Victor
  • 16,609
  • 71
  • 229
  • 409
0
votes
2 answers

Assigning data from SAS data set to variable (SAS E Guide 5.1)

I use SAS to execute queries, and sometimes send an email to my team afterward to confirm that the query has executed. However, I never really know if it was successful unless I check manually. For example, I have a SAS job that executes a stored…
Joshua Schlichting
  • 3,110
  • 6
  • 28
  • 54
0
votes
1 answer

Looping over array to create multiple datasets SAS

Dataset has 4 variables: id v1 v2 v3 I want to automate the creation of 3 datasets, each with 2 variables: id and one of the 3 variables from the original dataset. I know I want to use an array, but not sure exactly how to set up the macro…
Lisle
  • 1,620
  • 2
  • 16
  • 22
0
votes
1 answer

In SAS, how to execute a variable string as an if-statement (var = "if x = y")?

I have a data set with a variable named "Condition" that I want to use in the code. I'm guessing I need to do it in a macro but I'm still learning how to write macros in SAS. So if my data set is…
Andy
  • 11
  • 3
0
votes
1 answer

Limiting number of observations in SAS ODS output

I'm trying to limit the number of observations included in ODS output table. My attempt is pretty basic: OPTIONS NODATE number pageno=1 rightmargin=0.25in leftmargin=0.25in topmargin=0.4in bottommargin=0.4in; options sysprintfont=("SAS Monospace"…
S Cross
  • 17
  • 5
0
votes
1 answer

Create Data sets within Macro in SAS

I can create multiple data sets using the following way: data D3RGDPX (drop=BasePeriod BaseYear Forecast10Year) D3GDPX (drop=BasePeriod BaseYear Forecast10Year) D3BFIX (drop=BasePeriod BaseYear Forecast10Year) D3CPAT (drop=BasePeriod…
mustafghan
  • 169
  • 4
  • 15
0
votes
1 answer

subset data in sas using macro properly and append them to a file

I have some data sets that I wrote some code to clean according to some methods according to some biological literature and then I want to split it into day and night (because they must be analyzed separately). It worked but now I need to do this…
Jacob Ian
  • 669
  • 3
  • 9
  • 17