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 Two dimensional array with macro variables as dimensions

Can you help for this question please, How to define two dimensional arrays with flexible dimensions depending on macro variables in SAS? %LET Dim = &a.*&b.; ARRAY Spline{&a.,&b.} B1-B&Dim.; I tried with the above code but it gave these…
0
votes
2 answers

SAS libref not recognized in macro loop

I've run into an odd SAS quirk that I can't figure out - hopefully you can help. I have a simple macro loop that imports CSV files and for some reason if I use a libref statement in the "out=" part of the import procedure, SAS doesn't recognize the…
user2333453
  • 103
  • 1
0
votes
3 answers

SAS: attempting to build a loop for uploading multiple files

I'm attempting to build a loop in SAS to upload several files, and am running into a few issues to work through. Current code: %Macro Weatherupload(File=, output=); proc import datafile = &File; out = &output; dbms=dlm replace; delimiter=…
Dillon
  • 11
  • 4
0
votes
1 answer

what is the logic of this code in SAS Macros?

%let x = 15; %macro test; %let x = 10; %put x inside macro test = &x; %mend test; %test; %put x outside the macro test =&x; %put x inside the macro test =&x; i need to know what is value of test outside the…
ved_null_
  • 71
  • 2
  • 10
0
votes
1 answer

Creating datasets within Macro SAS

I have the following code: %macro MSA (Data=, Code=, MSAName=); data &Data; set NoDup; %if MSA = &Code %then %do; MSA_name = "&MSAName"; output &data; %end; run; %mend MSA; %MSA (Data=Bakersfield,…
mustafghan
  • 169
  • 4
  • 15
0
votes
2 answers

SAS differences in outcome between sql and proc means

I want to have a weighted average of some variable in a macro variable. My var is zindi&aa and my weight is wprm&aa I am trying to make sense of two ways of doing it : one with a proc sql proc sql noprint; select mean(zindi&aa. *…
Anthony Martin
  • 767
  • 1
  • 9
  • 28
0
votes
1 answer

How can I use different sets of date values depending on the date

I am looking to automate a daily report for my company but I have run in to a bit of trouble. The report gets updated only on the 2nd working day of each month. I found some code on the SAS website which works out what the 2nd working day of any…
Rossco2210
  • 13
  • 3
0
votes
1 answer

Trying to create new dataset using macro sas

I have the following code: %macro One (Data=, City=); data &data; set Dataset1; Var_new=.; if State = "CA" and CITYCODE = &City then output; run; …
mustafghan
  • 169
  • 4
  • 15
0
votes
2 answers

Getting a WARNING: Truncated record. but not able to figure out the reason

I have a macro dt_query , which will be called with different parameters... %let dt_start_date_sql = %dt_query(month,-1,sqlsvr); 65 %let dt_end_date_sql = %dt_query(month,0,sqlsvr); WARNING: Truncated record. 66 %let…
SAS_learner
  • 521
  • 1
  • 13
  • 30
0
votes
1 answer

SAS Macro to Combine Municipal Proc SQL Statements Based on Date Criteria

I have a series of proc sql statements which pull data for Active, Inactive and Lapsed customers. I end up with 3 tables. *Customers_Active *Customers_InActive *Customers_Lapsed Active: 0-12M purchaser Inactive: 13-24M purchaser, did not…
user2270911
  • 195
  • 1
  • 5
  • 18
0
votes
3 answers

SAS- Defining Page Breaks inside Macro

I am wondering if there is a way of defining when and where page breaks occur when using a macro to output data. I know within the various ODS tagests the "Startpage=NOW" can be used but that does not seem to work if a macro is used inside that…
Brad
  • 85
  • 12
0
votes
1 answer

error with quotes while passing macro variable to proc sql

I am trying to do following in macro: proc sql; select * from table1 where col1 like 'x%' quit; %macro temp(val=x); proc sql; select * from table1 where col1 like '&val%' quit; %mend; The problem is that to resolve the value of val, it has…
user2542275
  • 137
  • 1
  • 7
0
votes
1 answer

SAS MACRO: Create many datasets -modify them - combine them into one within one MACRO without need to ouput multiple datsets

My initial Dataset has 14000 STID variable with 10^5 observation for each. I would like to make some procedures BY each stid, output the modification into data by STID and then set all STID together under each other into one big dataset WITHOUT a…
0
votes
1 answer

Changed byte value solved this, but why? SAS: this range is repeated, or values overlap

My BI department just ran into the SAS error: this range is repeated, or values overlap. I found some links they looked at and found that there was an error in a macro. The error was that the length of a numeric variable byte value was changed from…
Sabeltiger
  • 13
  • 6
0
votes
1 answer

in SAS how do I get this %macro to evaluate the way I want it?

Greetings SAS experts, I have a lot of statements that will vary that are structured like this: if item = '0123' then e123 = data1; if item = '0541' then r541 = data2; the variable item contains character values that are numbers. I have a lot of…
user650738
  • 31
  • 1
  • 2
  • 5