All Questions
537
questions
5
votes
3
answers
7k
views
How do I delete tables that all have similar names
I want to use a SAS function such as
proc datasets nolist;
delete lib.temp_something lib.temp_something2 lib.temp_something3;
quit;
Is there a shortcut to delete all tables with the same prefix ...
5
votes
6
answers
10k
views
Split large SAS dataset into smaller datasets
I need some assistance with splitting a large SAS dataset into smaller datasets.
Each month I'll have a dataset containing a few million records. This number will vary from month to month. I need to ...
4
votes
1
answer
8k
views
SAS Macro variable in R
I am very familiar with the SAS programing environment. I am currently trying to learn to program in R. I have found that using SAS Macros reduces the amount of repetitive code in my programming. ...
4
votes
3
answers
12k
views
Conversion of SAS Macro Variable to time stamp
I am trying to convert SAS Macro variable to timestamp and stumped while conversion. The code which I am using is given below.
%let date = '03/15/2013';
%put %sysfunc(inputn(&date,datetime26.6));
...
4
votes
2
answers
438
views
Refreshing the macro library
I've been using a macro library so that I can use macros without compiling them first. The problem is that when I change the macro and save it, then refresh my filename for the macro lib, this is not ...
3
votes
4
answers
6k
views
Macro variable generating a space while creating a macro variable in Proc SQL
I'm creating a macro variable but when use the same macro variable in my Proc Report this macro is generating a space in front of the value
Select COUNT(DISTINCT USUBJID) into: N1 from DMDD where ...
3
votes
4
answers
3k
views
Resolving macro containing %eval in macro variable name, SAS
this is a toy example in order to help with a larger problem I have. It essentially involves using a %eval() macro when referencing a bigger macro variable name.
I have created a macro variable x_2, ...
3
votes
3
answers
13k
views
looping over character values in SAS
In Stata you can loop over a list of character values with the foreach command. I've been trying to do the same in SAS to no avail so far. I'm trying to run a series of data and proc statements over ...
3
votes
1
answer
11k
views
SAS Loop through list of macro variable
First off, I'm new so I apologize if this is not a good question. I searched but did not find something similar. I'm not sure my approach is correct so any assistance would be appreciated.
I'm ...
3
votes
3
answers
973
views
SAS: Rename a Macro Catalog
I want to store macros in a catalog. Doing so allows many macros to be shared with just a single file, as well as introduces a degree of separation from the user.
To store my macro, I run a program ...
3
votes
2
answers
99
views
SAS Define a Macro on a Unix Server
Hi I'm trying to define and run a SAS Macro on a Unix Server.
options symbolgen mprint mlogic;
*options nosymbolgen nomprint nomlogic;
rsubmit;
%let trend_MM = 1;
%let run_date = &sysdate.;
/*...
3
votes
3
answers
6k
views
SAS macro error: More positional parameters found than defined
Given the following SAS data set and macro, could someone please provide an explanation as to why the first 3 calls to the macro execute without errors but the 4th call produces the error message as ...
3
votes
4
answers
1k
views
SAS MACRO Quoting issue : passing string with macro trigger as macro parameter
Is this possible to pass a string with macro trigger as the macro parameter?
Please see the example code below:
options mprint;
%let string5='%abc%def%';
%macro test(string);
data _null_;
call ...
3
votes
3
answers
846
views
Get the ith word in a macro variable list
%let TableList = TableA TableH TableB TableG;
Words in &TableList are separated by ' '.
How can I retrieve certain word to do the following?
I do not know the number of words in the tablelist ...
3
votes
2
answers
3k
views
Passing SAS dataset column as macro parameter
I have a SAS dataset with values
yyyymm
201605
201606
201607
201608
201609
I am trying to find a way to pass these values one at a time to macro such that
do while dataset still has value
%macro ...
3
votes
1
answer
787
views
Read the return value from VBScript into SAS
I have a SAS program which requires many input files whose names vary each month. Rather than update the individual file names in Windows Explorer to hardcoded aliases in SAS or copy and paste the ...
3
votes
1
answer
83
views
how to record the moving direction is SAS?
I have a maze file which is like this.
1111111
1001111
1101101
1101001
1100011
1111111
a format $direction indicating the direction
start end label
D D down
L L left
R R right
...
2
votes
3
answers
14k
views
Difference between defining SAS macrovariables via %let and call symput?
I am not sure what the difference is between
%let m=product and
cal symput('m', 'product') is?
Aren't both expressions creating af macrovariable, m, which has the value product?
2
votes
3
answers
6k
views
Replacing Turkish characters with English characters
I have a table which has 120 columns and some of them is including Turkish characters (for example "ç","ğ","ı","ö"). So i want to replace this Turkish characters with English characters (for example "...
2
votes
4
answers
29k
views
Assigning a macro variable value to a data step variable in SAS
I am calling a macro inside a data step and assigning the macro variable to a data step variable as below.
The input for the macro goes from the input dataset which has some 500 records.
%macro test(...
2
votes
1
answer
156
views
Macro to call datasets and concatenate it
I know to how to call different tables from my folder. This is done with the function : %let x1 = libname.foldername. My problem is how to do it on 1000 tables with a simple macro
SAS
%Let Table1=...
2
votes
2
answers
13k
views
Create and use a list in an IF statement in SAS
User PomPazz post this answer for creating a list from input variables:
"You need to use a macro to "write" the SAS code for you.
This should do what you are looking for. It takes a space delimited ...
2
votes
1
answer
1k
views
Using SAS macros, is there a way to create variables with names that have spaces?
I'd like to use a macro to create a variable in my dataset. The variable name has spaces. Usually in SAS I would have to enclose the name with apostrophes: 'var_name'n . In macros, I've tried to mask ...
2
votes
3
answers
107
views
Execute SAS macro for many parameters
I use the following code to insert rows to the table:
proc sql;
create table business_keys as
select name, memname
from sashelp.vcolumn
where 1=0;
quit;
%macro insert(list);
proc ...
2
votes
2
answers
456
views
SAS option value to macro variable
I want to store the value of a SAS option in a macro variable so I can reset the option, not to the default value but to what it was before, like this:
options mprint &prev.;
Does anyone know how ...
2
votes
2
answers
386
views
SAS Macro to extract selected rows from table
I have a dataset having 20 observations and 6 variables ID, Gender, Age,Height,Weight,Year. All are numeric except gender variable. I would like to extract 10 observations starting from fifth ...
2
votes
2
answers
7k
views
Execute Macro inside SQL statement
The Situation:
I have a table mytable with two columns: tablename and tablefield:
|-----------|------------|
| tablename | tablefield |
|-----------|------------|
| table1 | id |
| table2 ...
2
votes
2
answers
395
views
Make A step in a SAS macro timeout after a set interval
I'm on SAS 9.1.3 (on a server) and have a macro looping over an array to feed a computationally intensive set of modelling steps which are appended out to a table. I'm wondering if it is possible to ...
2
votes
3
answers
3k
views
Using SAS sql to create macro variables
I'm using SAS sql to create some macro variables for later use and printing of reports.
I am creating some summary variables (mean, min, max, etc.) by group.
The following code works for the first ...
2
votes
1
answer
2k
views
Prompt: Date, %Sysfunc(year(&myvar.));
I have a SAS EG 7.1 program that generates reports on a monthly basis. The old process was very manual, where users, amongst other things, were asked to update a macro variable (&date.) with ...
2
votes
1
answer
158
views
SAS - Do looping from condition1 to condition2
I am looking to have a programme which cleans up some messy data I have, I am looking to do this for both the assets and liabilities side of the project i'm working on.
My question is there a way to ...
2
votes
3
answers
701
views
How to use/execute "Read command of unix in sas macro"
Below is the script which I am using to execute the "read sub" but unfortunately not able to get the desired result.
#!/bin/sh
{
echo '%macro read;'
echo '%sysexec ( echo -n "Sub setting condition:"...
2
votes
3
answers
591
views
SAS Call execute output changes every time I run it
I’m running a macro with a call execute in a data step.
What I want from my data step is the following:
Take a table, add a new column for every existing column (via macro) and finally add a new ...
2
votes
1
answer
3k
views
SAS Call a macro variable
I have a program that I want to run on several years. Therefore at some time I have to select my data
data want;
set have(where='2014');
run;
To try on several years, I have a macro variable,...
2
votes
3
answers
1k
views
Automating table/object name scan and search in SAS
OK I'll start with the problem:
I have product tables being created every week which are named in the format:
products_20130701
products_20130708
.
.
.
I'm trying to automate some campaign analysis ...
2
votes
1
answer
2k
views
SAS: Macro variable and string. Correct TableName
This is a part of macro:
%let mvTableName = "MyTable";
proc append base = &mvTableName data = TEMP_TABLE;
run;
And i can't find table in WORK :\
After that i check creation of table.
...
2
votes
1
answer
9k
views
How to use a basic SAS Macro Array?
Beginner question: I am trying to use SAS macro arrays as explained in this article: http://www2.sas.com/proceedings/sugi31/040-31.pdf, specifically in the section %ARRAY WITH DATA= AND VAR=. ...
2
votes
2
answers
1k
views
SAS V9.1.3 - Error when combining %INC and CALL EXECUTE
I am getting a resolution error with some SAS v9.1.3 code.
Here is some code I want to store in a .txt file (called problem2.txt) and bring into SAS with a %INC
%macro email020;
...
2
votes
1
answer
85
views
Macro with two arguments SAS 9.4
I have a table with 4 variables: State (Alabama, Arizona and Arkansas), County, PovertyRate and PopulationDensity. I want a short macro with two arguments(state and county) that will print the data ...
2
votes
4
answers
3k
views
substr function with macro variable name
I am trying to use substr function in SAS macros like this:
%let hg=Name;
data gg_;
set sashelp.class;
gh=%substr(&hg,1,3);
run;
and also I tried
data gg_;
set sashelp.class;
gh=%sysfunc(...
2
votes
2
answers
263
views
References to SAS date macros not working due to differing data types
hoping for some help on this one.
Currently, the query uses the below to create references for m1-m6 and d1-d6.
%let m1=1114;
%let d1 ='30NOV2014'd;
%let m2=1214;
%let d2='31DEC2014'd;
%let m3=0115;...
2
votes
2
answers
777
views
How to calculate conditional cumulative sum
I have a dataset like the one below, and I am trying to take a running total of events 2 and 3, with a slight twist. I only want to count these events when the Event_1_dt is less than the date in the ...
2
votes
2
answers
475
views
SAS: How do I transfer variables between IML statements?
Let's say I'm trying to do the following:
%macro test(a=);
%do i=1 %to &a;
proc iml;
b=b//(2*i);
quit;
%end;
proc iml;
print sum(b);
quit;
%mend;
%test(a=2);
In the code I'...
2
votes
1
answer
217
views
How to pass the value of a variable to an argument of a function in Macro SAS?
ID a1 a2 a3 a4 _1 _2 _3 _4 _5 _6 _7 _8 _9
1 _1 _3 _6 _9 8 5 9 8 6 10 2 1 4
2 _2 _5 _8 _9 10 6 2 7 10 8 3 5 9
3 _1 _2 _4 _8 3 6 1 9 6 9 3 0 4
... ... ...
2
votes
2
answers
278
views
sas how to make all variables in macro local?
In my code I've many macros inside others on many levels. Most of macro variables are the same (dates), but sometimes I'd like to run a macro with different date - then my variables collide.
How can ...
2
votes
2
answers
434
views
sas macro index or other?
I have 169 towns for which I want to iterate a macro. I need the output files to be saved using the town-name (rather than a town-code). I have a dataset (TOWN) with town-code and town-name. Is it ...
2
votes
1
answer
256
views
Do While, Do until all observation dates equal to today() sas proc sql
I have to run a report every morning, but cannot do until all the tables that I am querying from have been updated for that day.
I want to make a macro that does not continue with sas processing ...
2
votes
1
answer
404
views
SAS macros to import and apply macro from text file on csv dataset
I have a text file "Macro definition" which has two SAS macros definition. I would like to import them and apply on HTWT.csv data set. This dataset has 20 observations and 6 variables ID, Gender, Age,...
2
votes
1
answer
1k
views
Simply adding two macro variables in SAS
I'm currently trying to simply add two macros being created. But I'm struggling quite badly with this. It seemed very straight forward at the beginning but..
So here is what I'm trying to do..
%let A ...
2
votes
2
answers
884
views
SAS Call Symput - INTNX returning inconsistent dates
I'm trying to use the call symput below to grab the most recent Friday and Sunday from the previous week. For example, if I run it today (5/17/2016) then it should grab 5/13/2016 and 5/15/2016. ...