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

SAS Add 1 to flag if previous row value doesn't match with current flag following certain condition

I have a table that is being created, we will say that column 1 is YearMonth and column2 as Flag. YearMonth Flag 200101 1 200102 1 200103 0 200104 1 200105 1 200106 0 200107 1 200108 0 Note: First entry of flag…
user11505060
-1
votes
1 answer

SAS global variable for date

I want to create a sas macro global variable with current month in the format OCT i.e., only first 3 letters of current month are expected in the output in upper case. Please guide me.
-1
votes
1 answer

Create a dynamic dataset name with SAS Macros

I am working facing an issue while creating a dataset name by using macro variable. So basically I wanted to create Region_Jun_14 through macro variable. Jun_14 is current month and date. Any lead would be really appreciated :) CREATE TABLE…
vmaha13
  • 11
  • 1
  • 4
-1
votes
1 answer

Dynamically Name Datasets in Python Like SAS

I am scraping data from the web for multiple years (2007-2019). I want to output the data in different datasets called df_year, and have the year be the year of the data. In SAS, I could create a macro variable for the year, but not sure how to name…
-1
votes
1 answer

SAS Macro: Check a macro variable if value in a table

I have two macro variables: runasofdate with value '20190107' process_weekend that will be either 'Y' or 'N' Both macro variables are from an Excel config file and assigned using call symput. Then I have a table with list of local…
Recy
  • 11
  • 3
-1
votes
1 answer

use sum function with negative variable in sas

I'm new to sas and not able to figure what this statement does in the data step sum(column1, -(col2 * col3))
-1
votes
1 answer

How to find the mean and standard deviation of all numerical variables in a SAS dataset

Here's the question I'm working with: Write a single DATA step that takes an existing SAS data set and creates a new SAS data set for which each observation consists of the mean and standard deviation of the absolute values of all numeric variables…
-1
votes
1 answer

If condition and a proc sql inside a macro program

I have a control to verify. I want to write a macro variable who includes an SQL proc in case the condition is verified. Exemple: %Macro Control1(List) / minoperator mindelimiter=' '; %IF &Control1 in &List. %Then %do; proc sql; create table…
Mlk
  • 91
  • 8
-1
votes
1 answer

SAS quote a string for label usage

I want to QUOTE the following string '%LLY+' and use it as Y-axis in the plot. But I am always getting warning message from SAS saying that WARNING: Apparent invocation of macro LLY not resolved. or NOTE: The quoted string currently being…
qifengwu
  • 129
  • 1
  • 13
-1
votes
1 answer

Extracting data from SAS data set based on values with different length

I am looking to automate a process which has a sales dataset and a specific column named SALES CODE which is of 5 letters. Based on the input given by the user I would like to filter the data but the problem is the user can give multiple sales codes…
San
  • 1
-1
votes
2 answers

loop whole code many times on SAS program causes error

I have a long code about 5000 lines. When I macro this program, and loop a few times. It executed successfully but if I changed the loop to 300 times, the code started to cause the error, I can not figure out why it causes, %let Numberl=300; %macro…
SASPYTHON
  • 1,571
  • 3
  • 14
  • 30
-1
votes
2 answers

looping over macro variables in datastep

I need to loop over some macro variables in my data step i have tried to define the macro variable and build them dynamically in the data step like this DATA _NULL_; call symputx('_rbank_1',put(001,z3.)); call…
havmaage
  • 573
  • 7
  • 25
-1
votes
1 answer

Dynamically selecting variables from a dataset in sas

I am trying to read a data set that has columns like below: 1000 10001 1002 2000 2002 2004 2006 a b c d e f g b c d e f g h The format of the column names is number. I need to read this data and dynamically…
Arun Kumaar
  • 99
  • 1
  • 5
-1
votes
1 answer

How to specify dummy variable for categorical variable in SAS

I am performing regression where I make dummy variable for categorical variable. where I have a categorical variable i.e agecategory 1 2 3 4 5 I would like to know how can I define dummy variable of this categorical variable in SAS.
-1
votes
1 answer

SAS macro to change column names

how to use macro to change names of a table column ,except the ones that you point out.numeric type columns are added prefix "XC_" and char type columns are added prefix "XN_"
LeeKing
  • 71
  • 1
  • 7