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 Proc Report Title Error

I have an issue where by the do loop creates my reports however the title page where the macro is listed doesn't reflect the correct naming convention each time. It works for each of the bookmarks in PDF as well as the proc report itself. However…
Tinkinc
  • 449
  • 2
  • 8
  • 21
0
votes
2 answers

how to automatically join a bunch of sas datasets

I'm trying to functionise some of my SAS operations I have a bunch of tables which all have the same index (id) and the same number of rows Each time I call the function that I want to write, the number of tables can differ. I intend to store the…
shecode
  • 1,716
  • 6
  • 32
  • 50
0
votes
2 answers

Error in Macro Function

I'm using SAS Enterprise Guide. New to writing SAS macro functions. Nested a proc sql inside a macro. I'm trying to first check if a column exists and return the column number and then using the column number, to get the column name so that I can…
0
votes
1 answer

Why these many observations are created in the following program?

data test; infile cards dsd dlm=', .'; input stmt : $ @@; cards; T ;run; /*-----------------------------------------------*/ data test; infile cards dsd dlm=', .'; input stmt : $ @@; cards; Th …
mac_21
  • 113
  • 9
0
votes
0 answers

SAS not resolving &MacroVar

I have the following code: option nomprint; %let firstCurveLength = 50; %let macroVar=first; %put &¯oVar.CurveLength; The last statement printed to the log is: &firstCurveLength I don't understand why &firstCurveLength isn't resolved though,…
Max Power
  • 8,265
  • 13
  • 50
  • 91
0
votes
1 answer

Macro quoting issue in function style macro

This is a follow up question to this question. I'm trying to simplify the way we embed images into our HTML results. The idea for this was inspired by this other question . Basically what I am trying to do is to write a function-style macro (called…
Robert Penridge
  • 8,424
  • 2
  • 34
  • 55
0
votes
1 answer

Is not null in SAS Macro loop

Hi I am still struggling with SAS MACRO loop: %Let t1=12Mth; %Let t2=20; %Let t3=40; %Let t4=40; %Let t5=50; %Let t6=60; %macro Clean(time); data Milk1; set MilkNew; %Do I = 1 %to &time.; /*If MilkE=2, then MilkF should be 0 and MilkA should be…
Yukun
  • 315
  • 4
  • 15
0
votes
1 answer

How to map macro variables in SAS with existing variable in the table?

I have a table named as report, and there is a variable called ord which takes values 1,2,3...15. I have generated global macro variables &n1, &n2, &n3.... &n15 which are all numeric. I wish to add another column value into the table report, which…
Honglei
  • 1
  • 1
0
votes
1 answer

sas macro to count difference between two date strings & store the number in new variable

Parameters start_date, end_date & output_vars. Dates are charter string. How can I convert it in a macro? data _null_; start =; end = ; diff=end date-startdate; days = intck('day',start,end); weeks =…
Apache11
  • 189
  • 11
0
votes
1 answer

SAS - Macro variable within % statements

I have a SAS file that I maintain on a monthly basis. I often automate parts of the code with macro variables such as: %let currMth = 201511; But I am having problems using the macro variables within other macro statements. How do I do this? %inc…
Wolfspirit
  • 155
  • 3
  • 14
0
votes
1 answer

Use do loop index in macro variable definition

I would like to define multiple macro variables in a data step. In this case I would like to create the variables &buffer1, &buffer2, &buffer3, &buffer4. The number of buffers is variable, so I am not able to hard code the creation of these…
J Petersen
  • 162
  • 1
  • 13
0
votes
1 answer

SAS Macro Variable Quoted Concatenation

I am debugging a macro I am writing that will treat a string as either a prefix or suffix of a dataset name based on user input. Then, the quoted result will be fed into another process downstream. So if the user says Type=1 and provides the string…
pyll
  • 1,688
  • 1
  • 26
  • 44
0
votes
2 answers

create a macro variable about filename in SAS

This is the first step which would be used throughout all the project later: (a) Create a macro variable using a %LET statement called ‘directory'where you can type the name of the directory that contains all the files of interest for this project.…
DUKEANDY
  • 1
  • 1
0
votes
3 answers

Do Loop using CALL SYMPUT

Having some problems with Do Loop Concepts. I have a static date (can be any date for that matter) defined with - %LET DATE = %SYSFUNC(TODAY()); %PUT &DATE; I need to create a series of macro variables that hold values of that date (&DATE)…
SMW
  • 470
  • 1
  • 4
  • 19
0
votes
0 answers

Call SAS macro in a loop

I have a SAS macro ; And I have a dataset with one column and 100 observations. How can I loop over these 100 observations and call the macro, each time passing the value of the n'th observation to the macro?
Victor
  • 16,609
  • 71
  • 229
  • 409