Questions tagged [sas-macro]
A metaprogramming language used in the SAS suite to modify normal SAS code at run-time.
1,292
questions
1
vote
1
answer
24
views
I don't understand how SAS merge treats columns if you have the same column name in 3 tables with different values
I have a REC column that can be found in three tables: GRAV, ATTRI and SIN_TOT. I want to know in the final result of this code, SAS it takes the REC column of which table exactly? knowing that there ...
0
votes
0
answers
25
views
sum problem when converting SAS etape Data code to sql server [closed]
j'ai essayé de convertir un code SAS en sql server, mais j'ai eu un petit probléme dans mon code SQL server que j'arrive pas à resoudre , vous poouvez m'aider s'il vous plait sur la suite de ...
0
votes
1
answer
24
views
Macro not resolving as expected
I'm trying to resolve an macro which changes during loop execution since i have defined it inside a single quote it's not getting resolved
%do m = 1 %to 10;
proc sql noprint;
connect to POSTGRES (&...
0
votes
1
answer
40
views
macro error: A character operand was found in %IF condition
I am getting the "A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:
&no. = 4" error on the following code:
%...
0
votes
1
answer
36
views
SAS macro to loop through dataset variables and perform string matching
I need to search through the 15 variables of a dataset for a specific substring (the word "None"). When I use the code below for just one variable, I can get the results I want. However, ...
0
votes
3
answers
33
views
Populate data step name with today's date in SAS
I'm brand new to SAS and working from someone else's code as a way of teaching myself, so bear with me if the premise of my question is extremely basic. Also, I've seen a similar question asked ...
0
votes
1
answer
31
views
How to check that columns name and observations in a table will contain aplhabets ,number and underscore?
I want to create a macro that will check that table_name(dataset name), column_names and their observations will contain alphabets,number and underscore, if not (else) throw an error.
Thanks in ...
0
votes
1
answer
38
views
Referencing macro variable in a CASE WHEN statement
I have a proc sql statement which I am trying to expand to be as thorough as possible.
PROC SQL;
CREATE TABLE &CURRENT_ID._SCR (drop =
SDX
SPDS
CMPLV
CMPGD
Miss_Flag) AS
SELECT *,
CASE
WHEN SDX ...
1
vote
3
answers
36
views
SAS Applying Dataset of column names to a proc import
I have a very large dataset that I'm reading in, it is 2400 columns long. When I try and read this in via Proc Import it cuts off the variable names so instead I thought I could read in the column ...
0
votes
1
answer
37
views
SAS Nested %if %then %do statements
I'm running this as a bigger code and want to make it as automated as possible so I'm trying to set some macro variables. I'd like to have two conditions on setting some macro variables in sas, I've ...
0
votes
2
answers
38
views
No data found/modified. using SAS/sql server libname and function delete
I've tried to delete rows with month and year conditions in the ASO.TAB table knowing that the ASO lib is a SAS libname connected to sql server but I always receive No data found/modified. do you have ...
0
votes
1
answer
45
views
Create a variable based on n other variables
I have a dataset in SAS that has 10 variables on the basis of which I would like to create a new flag. If any of the class columns is greater than 0 then its name should come in the flag as given in ...
1
vote
2
answers
36
views
Write a code to generate a new .sas file from a sas code
I need help please help me, I want write a code to generate a new .sas file from a sas code and a new file at a particular location.
Thanks in advance
I have Extract excel sheet name in sas and want ...
0
votes
3
answers
52
views
SAS CODE to order variables Means from highest to lowest mean
I can't do the SAS code to order a set of variables means from highest to lowest.
I already got the means of each variables, but I can't get SAS to order the variables from highest to lowest mean.
I ...
0
votes
2
answers
73
views
SAS program to check file level controls on multiple files
This code is working perfectly when we pass single file but I need to achieve the same when I pass multiple files. If any file fails any macro condition it should be logged in the error.csv.
Here I do ...
0
votes
1
answer
35
views
create multiple columns in sas macro loop
I'm new to SAS and wondering if this is possible.
I'm using an existing table to create a wide dataset to create 36 columns, which representing months FROM 2021-2024
Each new column contain speeds. On ...
0
votes
2
answers
45
views
A character operand was found in the %EVAL function and Apparent symbolic reference %macro not resolved?
I have two errors in two SAS programs :
In program 1 the code can't read the expression 'IN' and in program 2 I want to store the modate of each date in a specific macro.
Program1:
%macro Execution;
...
0
votes
0
answers
36
views
How can I automate a verification and execution macro on several tables, each of which is processed with a specific SAS code?
"I've created some SAS code to check whether the SAS info-center tables are up to date for the program run. First, I check if we're in the execution range. Then, for each table, I check the table ...
0
votes
1
answer
51
views
validate multipe tablename and Error handling using sas macro
I have a main code file and macro code file and multiple tables and I want to validate the table _name and the same for column names, should be alphabets and underscore only by using macro and with do ...
0
votes
1
answer
24
views
How can I keep columns in common between two SAS tables to insert data?
I've made a code that allows you to insert data from the SI.SIA table, but sometimes if there's a new column added to the SI.SIA table my program stalls. Isn't there a solution to keep only the ...
0
votes
1
answer
20
views
validation of only alphabet and underscore in my tablename using sas macro
=====================================================================
I want to validate (sanity check) for my table name that only contains alphabets and underscore . If anything else then raise an ...
0
votes
1
answer
53
views
how can I know if the tables in the metadata are up to date to run my SAS code
I've created a SAS code that will be executed by the system on the first of each month.
How can I also add a condition to determine whether the library tables are already up to date on the same day ...
0
votes
1
answer
26
views
Is there a way to do an average over a whole SAS table with SAS?
Say if I had a table
column1
column2
column3
1
2
3
5
7
9
1
2
3
And I wanted to find the average so I wanted to sum everything up in the whole table and divide it by the number of data points, so ...
0
votes
2
answers
36
views
Conditionally Assign a Libname in SAS
I want to conditionally assign a libname in sas based on a already set macro variable, for one option of this if statement I also want to include a datastep. This is what I'm currently trying:
%if &...
0
votes
2
answers
63
views
Conditionally set a %let statement SAS
I was hoping someone could help with %if %then statements in SAS.
I want to conditionally set a macro variable so I was trying to do it this way:
%if &stress_test. = "Y" %then %let ...
0
votes
1
answer
39
views
Gradient decent
I am trying to perform gradient decent in data set with binary target variable flag_bad and iam facing many problems with %do statement and updating the parameters value
%let learning_rate=.01;
%let ...
0
votes
1
answer
69
views
SAS Create Macro variables using a macro
I have the following dataset:
A1 A2 A3
B 1 0.89606
B 2 0.10058
B 3 0.00336
C 1 0.88083
C 2 0.07205
C 3 0.04712
L 1 0.93198
L 2 0.06802
L 3 0.0000
R 1 0.8096
R ...
0
votes
3
answers
43
views
Why is it looking for formats ... and where are they? (SAS)
I'm trying to run a macro (mcartest). Here is the beginning of the code (full code is here, although I modified it to allow entering options in the macro call):
macro mcartest (data=,items=);
/* ...
1
vote
1
answer
81
views
SAS proc freq or proc sql to obtain frequency of a subset of data and whole data
I am trying to obtain frequency based on two different datasets (with their subsets). Consider the following example
DATA Group1;
INPUT Subject_ID education;
DATALINES;
1 LowerPrimary
2 Secondary
3 ...
0
votes
2
answers
38
views
Extract only file_path from SAS variable
I'm looking to extract just the directory path from a File_Path variable, excluding the file name in SAS. Can someone assist with this
/start_file_pth/data/sg/prod5/file_path/dataset1.sas7bdat.gz
/...
1
vote
3
answers
45
views
2 inputs into do loop in SAS
I need to create a sas do loop that will reference two moving values. This do loop will apply to a macro.
The Macro will look as follows:
%macro test (date1, date2);
DATA WANT;
SET HAVE;
IF INPUT_&...
0
votes
0
answers
44
views
Why is proc univariate failing for certain variables?
I'm calculating 'outliers' for a bunch of numeric variables.
This includes running a proc univariate to calculate the 1st and 3rd quartile as well as the interquartile range and later using these in ...
0
votes
2
answers
43
views
SAS Conditionally Call a Macro
I have a macro called "checks" and I would like to only call it when a previously defined macro variable (called run_type)= model. Here's what I've tried so far:
%if &run_type. = 'Model' ...
0
votes
2
answers
32
views
How to create looping macro in SAS/ Proc SQL
I need to write code that performs the same action over and over, but using a different macro variable name each time. I've done this before, but can't quite remember the syntax.
Summary: I need to ...
0
votes
2
answers
67
views
How to use SAS multiple Macro variables in procedure block using loops only if it exist
I created multiple macro variables using call symput using data values and I wanted to use them in procedure block using loops in macro and it's not working out for me.
Creating macro variables;
...
0
votes
2
answers
43
views
How to write macro that creates global variable from another global variable and macro parameter
I have global variable &project_path and need to write macro %set_path that will create another global variable which is equal &project_path\parameter. In my case name of new variable have to ...
0
votes
2
answers
33
views
SAS: Making a new column from a value of rows and retaining those values through every unique request ID
i have an example dataset here.
enter image description here
i want to make a new column named approver by extracting the "to_user" values if the workflow status contains "approval"...
0
votes
1
answer
102
views
How to get sas datetime in this format 2023-07-19 00:00:00 from this 19JUL2023:00:00:00
Hi I need to datetime in 2023-07-19 00:00:00 format from this 19JUL2023:00:00:00
data _null_;
from_batch_dttm = intnx('minutes', dhms(datepart(1958774400), int(27/4), mod(27,4)*15, 0), -15 * 192);
...
0
votes
1
answer
27
views
How can I loop through a list of %let statements?
I have five groups of %let statements I would like to loop through. I have been commenting out each group but I just realized I have to do this for about 30 other groups. Here are the five groups I ...
0
votes
2
answers
37
views
Merging three tables based on columns
I've 3 tables in SAS having a 1000 column that I want to merge together as
table_a
obj_Id | value1a | value2a .... | value1000a
1 | T1 | T1 | T1
2 | T1 | T1 ...
-1
votes
3
answers
95
views
SAS how to replace a string with the name of a macro variable
I need to import multiple years' access tables into SAS. In each year's ACCESS DB, the table name has year as the suffix. For example: table2021.
I first define a macro variable year. Then I am trying ...
0
votes
2
answers
29
views
Is there an alternative to using DATALINES that works within a macro to put text into a dataset in SAS EG?
Objective: I'm trying to print out a comment that users can see on the Results tab in SAS EG after running an existing macro.
Issue/Question: The problem I'm running into is that DATALINES doesn't ...
0
votes
2
answers
63
views
How to create date macro variable based on the last date WITH data
I'm quite new to SAS and need your help regarding creating date macro variable.
I have 6 tables at the moment and all of them are refreshed on daily basis. Each month i'm trying to get the data with ...
0
votes
2
answers
70
views
SAS - Macro - Column names with spaces/punctuation marks troublesome when sorting alphabetically
I have a big table in SAS where columns represent all the countries in the world. I have created it through long-to-wide transpose and I am representing a value for each ID in each respective country -...
1
vote
2
answers
69
views
catx function where columns are null
I am working with catx function in sas enterprise guide.
When I want to concatenate 2 columns I am using
catx('-',column1,column2)
It works fine but when both column1 and column2 are null it still ...
0
votes
1
answer
32
views
Importing Excel spreadsheets by referencing spreadsheet names from a dataset
I have a SAS dataset called "Filenames" with a variable called "memname" that stores the list of file names, i.e. 'Spreadsheet 1.xlsx', 'Spreadsheet 2.xlsx' etc.
This list is ...
0
votes
1
answer
86
views
SAS Passing Multiple User Input Values to Macro Variable
I am using SAS Web Report Viewer where I have an interface from which end users can select the multiple values as an input to a macro variable. However, when I check the SAS Logs I see that only the ...
0
votes
1
answer
63
views
SAS Running Multiple Macros based on Variable value passed through as a list
I have a query where I need to run multiple macros based on a condition. The condition is that if the value of a variable is X then macro 1 should run, if the value of the variable is Y then macro 2 ...
0
votes
1
answer
88
views
SAS Format could not be loaded
Good morning,
I have a small problem in a SAS code that I don't understand, what exactly is it and how can I solve this problem? the code is executed by the platform SAS knowing if I execute on my ...
0
votes
1
answer
94
views
Convert SAS date to character inside macro
I have a SAS date in date9 format that I want to convert to character variable with format yymmdd10. This works fine using put function (1), but when I instead use %sysfunc(putn()) - so I can use ...