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

How to write macro for importing multiple excel files(xlsx) in sas and append it

I am having some 50 excel files (xlsx format) to be imported to sas and then need to append it for analysis. All the excel files header are same i.e., the variable names are same for all the file. I need macro for importing and appending all of them…
Wasim raja
  • 13
  • 2
  • 5
0
votes
1 answer

SAS Populate table with PROC SQL INSERT statement and do loop

This is for an epidemiologic project. I wanted to calculate disease frequency rates in the years 1961 to 2013 among different populations: men of all ages, men over 50 years of age and the same two cases for women. First, I imported a population…
s.erhardt
  • 77
  • 1
  • 3
  • 9
0
votes
2 answers

SAS Macro - create a running macro as concatenation of another set of macros

I have a macro related issue that I’m currently struggling to develop and understand. Any pointer on resolving this would be greatly appreciated :-) It goes something similar below: I have a ‘n’ [variable] number of macro variables ‘Key’ which…
0
votes
1 answer

How to write a sas code to read file in different folders?

I am wondering is it possible to write a macro to read file in different folders. Like for example, I have 100 folders and within each folder, it has another folder, within the sub folder It may contain a txt file that I want to read with SAS. New…
gyambqt
  • 11
  • 3
0
votes
1 answer

How to use a macrovariable as string?

I want to do the following request : data _null_; call symputx("test",findw(' x y z ','x')); run; using a macrovariable instead of the ' x y z ' part, i.e. data _null_; call symputx("test",findw(&mv,'x')); run; where mv is a…
Vincent
  • 955
  • 2
  • 15
  • 32
0
votes
1 answer

Create Program Code out of excel table in SAS

For a Macro, I want to create an automated ATTRIB Statement. I have an exel Table with all variable names, formats, lables and lengths. Now I want SAS to read each row and pass it into: %LET Format_VARIABLE = FORMAT = &For LENGTH = &len LABEL =…
user3614882
  • 185
  • 1
  • 1
  • 11
0
votes
0 answers

Assigning a SAS statement to a macro variable

I have a dataset that contains the names and attributes of variables that I want to define for a dataset within a macro. For example: variable_name = "filedate" variable_length = 8 variable_label = "Date file was loaded" variable_format =…
at_sea
  • 143
  • 1
  • 1
  • 4
0
votes
1 answer

How to export SAS dataset to XLSX, by category, using macro variable?

I have a large data set that has approximately 100 names of managers. Now, I need to export the data by manager name so that I have a single dataset for each manager. I am able to use a macro to create a separate dataset for each manager…
kstats9pt3
  • 799
  • 2
  • 8
  • 28
0
votes
1 answer

How to run/not run SAS or SQL code based on conditional output?

I have a SAS program with a macro that will output a different list of variables based on the input criteria. For example, with %MACRO(OPTION1), I get three variables, but with %MACRO(OPTION2), I get four variables. The name of all of the variables…
vdiddy
  • 85
  • 1
  • 9
0
votes
1 answer

Event study macros returning major errors

Hi I'm pretty sure my code is completely wrong. I'm try to run a macro that performs an event study when firms are included into a portfolio and then removed to measure the average change in the model coefficients. Here I've tried to look at just…
Hamish
  • 35
  • 1
  • 7
0
votes
1 answer

SAS macro program : accounting for database indexed by both numbers and characters

I am working on a project in wich i have data at a particular geographical level. Due to historical reasons, these areas are indexed as : 01 02 ... 19 2A 2B 21 ... 95 I have a program I want to run on each of these areas, for which the database is…
Anthony Martin
  • 767
  • 1
  • 9
  • 28
0
votes
1 answer

SAS macro output file naming conventions

I have a sas macro which is dependent on two varying variables Age and Year represented by &Age and &Year respectively. I want to run the macro for each combination of the ages 15-18 and years 2007-2010 and wish to create an output table for each of…
user2568648
  • 3,001
  • 8
  • 35
  • 52
0
votes
2 answers

How can I use %SCAN within a macro variable name?

I'm trying to write robust code to assign values to macro variables. I want the names of the macro variables to depend on values coming from the variable 'subgroup'. So subgroup could equal 1, 2, or 45 etc. and thus have macro variable names trta_1,…
Dawnoak
  • 25
  • 2
  • 5
0
votes
2 answers

sas_ variable value inside a like in a macro

I need to use the following code inse a macro: proc sql; select name into :lista separated by ' ' from dictionary.columns where libname='LABO2' and name like 't1_%' and name like "%5"; quit; But when I write: %macro prue(numero); proc sql; select…
GabyLP
  • 3,649
  • 7
  • 45
  • 66
0
votes
1 answer

Using SAS and Linux to send email with reference to macro

I am trying to send an email using SAS from within Linux, In the body of the email I have a reference to a macro. * store &a in macro for use in email; proc sql noprint; select tot_sendt into :a from tot; run; * sending email; filename m…
Alexander
  • 624
  • 2
  • 7
  • 18