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
2 answers

SAS-Writing Multiple Tables to one XLSX Workbook w/ 2 tables per sheet

I am new to SAS and am having some issues exporting data. I have written a macro to generate some summary tables based on a certain ID. The macro creates two tables for each ID identified in a particular proc sql query. I can write out the last…
Brad
  • 85
  • 12
0
votes
2 answers

Loop to read fixed record number of records at a time from a dataset until all the records are read

I'm working in the sales department of a company and every month we have some products which sales revenue are negative. My job is to extract those products ID to analyse them. I use WPS which uses SAS language. So I need first to extract the…
0
votes
1 answer

Global macro variables (created with CALL SYMPUTX) won't resolve properly within SAS macro program

I'm very new to coding macros in SAS, so I'm mostly looking for a push in the right direction. I'm trying to create a big macro program, and within it I'm using CALL SYMPUTX to create several global macro variables that I reference within the…
mrt
  • 223
  • 2
  • 12
0
votes
1 answer

quote array element inside macro do loop

I can call the macro VIO by %VIO(Dow=Fri,Hour=8) without error. Now I want to nest the call macro inside a do loop. Here's what I have tried but no luck. %macro trythis; data _null_; array ay[3] $3 ('Fri' 'Sat' 'Sun'); %do i = 1 %to…
Lovnlust
  • 1,507
  • 3
  • 29
  • 53
0
votes
1 answer

Macro variable wont resolve with underscores

Having an issue when trying to get macro variables to resolve inside a macro definition when using underscores. I would like to keep the naming convention I have here but need the macro variables to resolve to do so. What am I missing? %macro…
Lyle
  • 219
  • 1
  • 4
  • 12
0
votes
3 answers

How to call a macro variable based on a condition

I have a dataset in SAS with a variable condition, that can take values in "01",...,"20" several variables indexed by i, for instance var01, ..., var20 What i want to do is to create a new variable total which is equal to vark if condition=k. I…
Anthony Martin
  • 767
  • 1
  • 9
  • 28
0
votes
3 answers

Holding Sampled Macro Variable Constant

Hopefully a simple answer. I'm doing a simulation study, where I need to sample a random number of individuals, N, from a uniform distribution, U(25,200), at each of a thousand or so replications. Code for one replication is shown below: %LET U =…
Ryan W.
  • 21
  • 4
0
votes
1 answer

Macro looping over columns in SAS broken by ods

I just found that ods graphics / reset; broke my loop. I am still curious why this happened and if there are other potential similar pitfalls. Objective: I want to loop over columns in SAS and provide a plot where the x variable remains…
Wes McClintick
  • 497
  • 5
  • 14
0
votes
1 answer

Composing a SQL statement with SAS MACRO code, using %put and cats

I want to write a macro that run an append the result of 10 queries, which I generate with SAS macro code. %MACRO APPENDTEST; PROC SQL; %DO I = 1 %TO 12 CREATE TABLE WORK.APPENDTEST AS SELECT t1.OrderID, t2.Name,…
Jayesh Menon
  • 59
  • 1
  • 5
0
votes
1 answer

Unable to match macro variable with dataset variable

The character variable in dataset never matches with the macro variable. The %IF loop never comes true. Kindly advice. I am trying to match by months and accordingly trying to create array and put counts only for specific months. Not working…
Rajat Panda
  • 129
  • 1
  • 3
  • 14
0
votes
1 answer

Writing a macro in SAS to create a table

Very new to SAS Programming. Want to start with something simple - writing a macro that run an append query. This is all I have managed to figure out. Where am I going wrong? %MACRO APPENDTEST; PROC SQL; CREATE TABLE WORK.APPENDTEST AS …
Jayesh Menon
  • 59
  • 1
  • 5
0
votes
2 answers

pass value of the dataset sas to a macro

i'm learning sas macro language but i have a problem i wrote a macro: %macro avg_acceleration(mark_type, avg_acceleration, mark_angle); %if &mark_type='A' %then %sysfunc(abs(&avg_acceleration/%sysfunc(cos(%sysfunc(abs(&mark_angle*(…
0
votes
1 answer

Conditionally print titles in SAS?

I want to display different titles for different variables that go through my macro. %macro mplot(dsn,vn); title1 'hey!'; %if "&vn"="" %then title2 "Ooos" justify=left; %else title2 "Ooos &vn" justify=left; title3 "this line"; %mend…
Lovnlust
  • 1,507
  • 3
  • 29
  • 53
0
votes
1 answer

dropping variables using a macro variable containing list of varnames

Total beginner at SAS. I wanted to drop a list of variables from my inputds. This list itself is present as observations in another dataset. After doing some googling, I found this excellent paper on the…
vagabond
  • 3,526
  • 5
  • 43
  • 76
0
votes
1 answer

export to excel with excel tagsets.

I am thinking to export the dataset's contents to an excelsheet by excel tagsets, However I am writing the code 5 times for 5 datasets. I want to write a macro which connects the list of variable from the library to the list of datasets so that I…
user3658367
  • 641
  • 1
  • 14
  • 30