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
5
votes
2 answers

Concatenate quoted macro variables

I'm just trying to concatenate two quoted macro variables but there doesn't seem to be an easy way. Say we have: %LET VAR1="This is not the greatest song in the world"; %LET VAR2="this is just a tribute."; %LET TRIBUTE=%SYSFUNC(CATX(%STR(…
Pane
  • 555
  • 2
  • 7
  • 20
5
votes
2 answers

Using SAS to delete a text file

Am looking for a piece of code, preferably OS independent and macro based, for deleting a text file (or any file for that matter)
Allan Bowe
  • 12,306
  • 19
  • 75
  • 124
4
votes
3 answers

Transform literal date parameter to SAS date value in macro

I want to create a SAS macro which takes a literal date (eg. '31may2011'd) as parameter. Inside the macro I want to transform this into a SAS date value (eg. 18778). %macro transLiteralDate2Value(literal=); %put literal = &literal.; %put…
TechnoCore
  • 1,394
  • 2
  • 16
  • 21
4
votes
1 answer

SAS Macro-variable reference concatenation

The following code reads in a cellphone bill from an excel file and do a lot of cleaning / reports. %LET month = March; .......... PROC IMPORT OUT = PHONE.marchmin DATAFILE = "D:\Data\cellphone\MarchBill.xls" DBMS = EXCEL …
DataParadigms
  • 437
  • 2
  • 11
4
votes
1 answer

Inconsistent Macro Variable Data Type

I'm trying to make a simple macro that checks whether a specific macro variable is either missing or does not exist. Normally, this would require two statements: a %symexist, and if it does exist, additional logic to detect whether it's a null…
Stu Sztukowski
  • 10,597
  • 1
  • 12
  • 21
4
votes
1 answer

SAS Metadata DATA STEP Functions

I want to know why is the metadata_getnatr function is used with metadata_resolve function when we are trying to read the metadata through data step functions. For example: in the code that is covered in the link Reproduced Here: Example 1: Using an…
4
votes
3 answers

Macro variable has different value within DATA Step. Why?

I had reason to process different variables of a given data set using a repetitive process. To solve this problem, I wrote a macro whose input would be the particular variable of interest. The macro would then process only that variable. However,…
Lorem Ipsum
  • 4,020
  • 4
  • 41
  • 67
4
votes
1 answer

SAS: How do I Store a Macro in a Catalog

This is a follow up question to a previous post. I am trying to store a macro in a catalog as outlined by these articles, in addition to the resources cited in my original post: PROC CATALOG, the Wish Book SAS® Procedure Ways to Store Macro Source…
Lorem Ipsum
  • 4,020
  • 4
  • 41
  • 67
4
votes
2 answers

Why does the %str in `%str(%inner_macro())` not work?

%str should pass a string as one parameter to a sas macro, even if it contains commas, but that apparently does not work if the argument of %str is in it self the result of a macro? I get ERROR: More positional parameters found than…
Dirk Horsten
  • 3,753
  • 4
  • 20
  • 37
4
votes
2 answers

Trying to get file attributes (file size , create date time and last modified date time) in SAS

I'm using following macro to get Linux file attributes using SAS. I'm getting values for size and Last modified time but not getting any values for "Create Date Time". %macro FileAttribs(filename); %local rc fid fidc; %local Bytes CreateDT…
SAS_learner
  • 521
  • 1
  • 13
  • 30
4
votes
3 answers

SAS macro quoting: pass equals sign as macro argument

I am writing a macro that at some point calls some proc SQL code. I want the user to be able to specify arbitrary proc sql options (e.g. inobs=100 could be one of the input arguments to my macro). I am having a very hard time quoting an argument…
jaamor
  • 317
  • 3
  • 15
4
votes
4 answers

How to prevent CATx functions from evaluating expression

When calling CATT() function with %sysfunc, is there a way to stop it from evaluating an expression? For example given the code: %let date=10-13-2015; %put %sysfunc(catt(The date Is:,&date)); I would like it to return: The date…
Quentin
  • 5,960
  • 1
  • 13
  • 21
4
votes
2 answers

removing single quotation marks from a string in SAS

I have a requirement to read the string with both single quotes and without quotes from a macro retrieve_context. While calling the macro, users can call it with either single quotes or without quotes, like below: %retrieve_context('american%s…
Naga Vemprala
  • 718
  • 3
  • 16
  • 38
4
votes
1 answer

SAS macro ERROR 180-322: Statement is not valid or it is used out of proper order

I'm trying to use SAS macro language on my company's SAS Server. The rest of the (SAS-base) code works fine, but macros don't. Even a simple %let causes an error (this is the first line in the program): 5789 %let pgm = XXX ; - …
ajl4j
  • 41
  • 1
  • 3
4
votes
3 answers

SAS: export data to multiple csv file by year

I have a dataset in SAS, which contains 20 years of data. I want to export to csv file for each year. Is there any easy way to do it? Here is what I'm doing for one year now (which is naive): proc export data=ds (where=(year=2011))…
SDF
  • 71
  • 1
  • 1
  • 4
1
2
3
84 85