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

running sas filename pipe in unix

I have the following piece of SAS code that I run on Windows and works well. But now I am looking to run it from unix. I guess multiple things could go wrong here -- initially I was figuring out about double quotes in the filepath definition that…
rajvijay
  • 1,641
  • 4
  • 23
  • 28
0
votes
1 answer

SAS macro to create variable ratios

I am trying to create a SAS macro that I can call for calculating ratio of variables. Here is how I have defined the ratio and used in a SAS dataset. I am getting error. What I am doing wrong? Thanks. %macro ratio(num, den, ratio); %if &den = .…
Zenvega
  • 1,974
  • 9
  • 28
  • 45
0
votes
1 answer

"XLSX file does not exist" error when using SAS Macro & Proc Import to import multiple .xlsx files at same time

I have a sas macro that use proc import to load multiple .xlsx files and it worked pretty well before. Today, I have a bunch more .xlsx files files that need to be loaded. So, I used the same macro idea. But this time it created a problem and…
QY Luo
  • 331
  • 1
  • 4
  • 11
0
votes
1 answer

SAS Loop for renaming variables

I want to replace values of some variables and rename them. Basically, I have many variables called f2 f3 f4 and so on up to f1065. The logic is as folllows: I need to replace values of variables f14 f18 and so on by 4 up to f54 by values of…
user3812923
  • 39
  • 1
  • 4
0
votes
1 answer

SAS Maco Program Char To Numeric

Hello I am trying to convert the dates in this program into numeric, the program generates dates 12 months as of today. i want the result to look like the first column "date0" 20140731 however i want the date0 column along with every column that is…
Tim
  • 13
  • 2
0
votes
1 answer

Leading space error when using %SYMEXIST

I am using %SYMEXIST to check if a macro variable exists and then continue or skip based on the result. It sounds so simple but SAS is throwing errors for all the approaches I have tried so far. &num_tables is a macro created from a dataset based on…
rom
  • 81
  • 4
  • 10
0
votes
1 answer

Generate proc import logs for multiple files to a pdf

I have written a SAS macro that imports all the excel files in a folder and it works. What I want to do next is - send the proc import logs or results for all the excel files to a single pdf. My SAS code looks like this: %macro readxls…
rom
  • 81
  • 4
  • 10
0
votes
1 answer

SAS - Automate Change in Data Source to Provide Report

I currently have a program that Generates a full report (Data Manipulation, Analysis, Formatting, Excel output) based on a few internal parameters. I would like to build a tool or Macro that will iterate through 6 data sets, and provide a report…
BGDev
  • 135
  • 1
  • 8
0
votes
2 answers

SAS DI (Data Integration): Inserting a Data in an existing Table

I have a program in SAS 9.3 (please refer below) that I need to do in SAS Data Integration Studio: %macro sqlloop; Proc SQL; Select distinct(DATE) into :raw_date from RAW; Quit; %DO k= %sysevalf("&raw_date"d) %TO …
0
votes
2 answers

Get data filtered by dynamic column list in SAS stored process

My goal is to create a SAS stored process is to return data for a single dataset and to filter the columns in that dataset based on a multi-value input parameter passed into the stored process. Is there a simple way to do this? Is there a way to do…
Scampbell
  • 1,535
  • 14
  • 24
0
votes
2 answers

How to assign a value to a macro in datastep in a loop SAS

So I am trying to do something like this: data temp1; set temp; do i=1 to 10; call symput("var1", i); end; array x(*) x_&var1 to x_&var10; .................... run; I am trying to assign the value of i (1 to 10) to macro…
user3147731
  • 103
  • 1
  • 1
  • 7
0
votes
1 answer

Access URL in SAS and stored data in dataset and JSON file

I am trying to access a URL and want to store data into a dataset and output file as JSON.. I just want to fetch URL data and store as a JSON file But my question has two part...... If url response data is already as a json format…
goldenbutter
  • 575
  • 2
  • 12
  • 25
0
votes
1 answer

SAS - Macro error within %if expression

I wrote this code: %macro puntos_evol; %let hoy = day(today()); %if &hoy = 14 %then %do; data prueba; mes_1 = intnx("month",today(),-1, 'E'); format mes_1 date9.; run; %end; %else %do; data salida; dato='no valido'; run; %end; %mend…
user3129222
  • 3
  • 1
  • 2
0
votes
1 answer

Unable to resolve macro

proc sql noprint; select count(distinct USUBJID) into : N1 - : N4 from DM where upcase(ARM) ^= "SCREEN FAILURE"` group by ARMN; quit; %macro TOTAL(name=,num=); %do i=1 %to #` %if ARMN=&i %then TOTAL=…
Nimit_ZZ
  • 495
  • 4
  • 10
  • 21
0
votes
1 answer

Utility to insert row in any sas dataset

I want to create a unix utility to insert 1 row into a sas dataset. When run, this scipt will ask user to insert value for each variable in the dataset(preferabely telling him the type and length of the variable). It will then pass these values to…
siso
  • 135
  • 1
  • 1
  • 7