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 passing a variable to a conditional macro

I can't figure out how to pass to a conditional macro the values of a dataset variable. Let's say we HAVE: data HAVE; input id name $ value ; datalines; 1 pluto 111 2 paperino 222 3 trump 333 4 topo 444 ; run; I would…
arj
  • 713
  • 2
  • 12
  • 26
0
votes
1 answer

SAS 9.3 passing a variable with spaces to a macro

I need to pass a variable that contains spaces to a macro. And use this variable to make some logic and to buid a new column inside the macro. I've tried something like: %MACRO func(var); if first.id then &var = 0; retain &var; if descr…
arj
  • 713
  • 2
  • 12
  • 26
0
votes
1 answer

Repeat several datasets and proc sql

I have program with data sets and proc sql. At the end of the program I would like to check final value and decide if the part of the program should be executed again with different parameters or the value is ok. Is there a way I can do loop…
mical
  • 3
  • 1
0
votes
1 answer

SAS Code for dynamic date

Currently I am working on a project in sas. We are producing the reports based on data from November2015. I need to import that file which has name //consumer accounting/Reports/SAS Reports/20151130/M0ED1 for November data. Next month it will be…
shankar
  • 63
  • 1
  • 8
0
votes
1 answer

How to not round values for a division with variables in SAS

I have two numeric variables in SAS: %let var1=10; %let var2=8; I have to do the division between the two, but if I do: %let var3=%eval(&var2/&var1); %put &var3; the result is 0. Because var2 is a subset of var1 and by default the system rounds…
0
votes
2 answers

Macro Automization via Prompts in SAS EG

here is my table data: ax bx cx dx ex fx 1 2 3 4 5 5 2 3 5 1 0 5 3 7 8 9 1 4 here is my basic code %macro example(c= , b= ,a= ); data temp; set data; diff = &c-(&b+&a); run; %mend example; % example(c=cx ,b=bx ,a=ax) I want…
Jonsi Billups
  • 133
  • 1
  • 3
  • 15
0
votes
1 answer

SAS intnx quarter variation

sorry it is probably a very simple question, but I can't seem to find an answer to it. Say, we want to create a table that contains 4 quarters back from the previous month: %macro asd; %let today = %sysfunc(today()); %let quarter_count_back =…
Kvadich
  • 17
  • 6
0
votes
2 answers

SAS remove all but one duplicate record in sas

data emp; input empID; cards; 2 3 2 4 3 5 3 2 run; I want to write proc sql delete query to remove all duplicate records but keep one so that dataset will have only following records. I want to do it using delete query, don't want to create…
mac_21
  • 113
  • 9
0
votes
2 answers

Multiple OR comparison

I have a group of variables , say b1-b30 and i need to test same condition on same variables among themselves like, if b1='a' or b2='a' or b3='a'.. and so on. is there any solution in SAS macros or using of sas arrays to do this task to avoid…
ved_null_
  • 71
  • 2
  • 10
0
votes
1 answer

How to add macro in SAS to the date variable to create a dataset for each month separately?

How can I add macro to the below code to do the same thing for each month of the year separately? For example, I'd need to create sourceg.trades_nov2008 as well. Thank you. data sourceg.trades_dec2008(drop=dt); set sourceh.trades_: indsname=ds_name…
Betsy B
  • 77
  • 2
  • 11
0
votes
1 answer

SAS macro with help option

I am trying to create a macro with help option also like below: %macro now(gg,datas); %if &gg=help %then %do %put; %put %str(hello); %goto exit; %end; proc print data=&datas; run; %mend; So when I call the macro with help %now(help) the…
user3658367
  • 641
  • 1
  • 14
  • 30
0
votes
2 answers

SAS Macro - Array

%macro nextNB(ds); %local dsid nv rc; %let dsid = %sysfunc(open(&ds)); %let nv = %sysfunc(smallest(2, &dsid)); %let rc =%sysfunc(close(&dsid)); &nv %mend nextNB; %put %nextNB(WORK.TEST); &dsid returns a dataset with values 5, 7 and 9. How do I…
0
votes
3 answers

Global variable in SAS EG

I have written two different SAS EG programs under the same project. The first one is to estimate a parameter, say A, which will be used in the second program. At the moment, once first program finish running, I manually set the parameter %let A =…
Ben10
  • 121
  • 1
  • 13
0
votes
2 answers

SAS - Comparing observations within a group to pick values

I have 4 columns in my SAS dataset as shown in first image below. I need to compare the dates of consecutive rows by ID. For each ID, if Date2 occurs before the next row's Date1 for the same ID, then keep the Bill amount. If Date2 occurs after the…
Keneni
  • 705
  • 5
  • 12
0
votes
1 answer

Checking whether the DS has variable value if the variable has missing values then drop the column

am passing a DS in macro parameter with var= if its corresponding variable has same value but the variables has all missing values then drop it. DATA details; INPUT id name $ dept $ salary; datalines; 01 John . 10000 02 Mary . 20000 03 Priya .…
Apache11
  • 189
  • 11