Posts

Showing posts with the label call symput

Mastering Global and Local Macro Variables in SAS: Essential Techniques and Best Practices for SDTM Programmers

Mastering Global and Local Macro Variables in SAS: A Detailed Guide for SDTM Programmers Mastering Global and Local Macro Variables in SAS: A Detailed Guide for SDTM Programmers In SAS programming, especially when dealing with complex tasks such as SDTM (Study Data Tabulation Model) dataset creation, macro variables play a critical role in automating processes and managing large amounts of data efficiently. Understanding the distinction between Global and Local macro variables, and how to use them appropriately, is essential for writing clean, maintainable, and robust code. What are Macro Variables in SAS? Macro variables in SAS are placeholders that store text strings, which can be reused throughout your SAS programs. They are part of the SAS Macro Language and are used to make your code more dynamic and flexible. By using macro variables, you can avoid hardcoding values and make your code easier to modify and scale. There are two pri...

CALL SYMPUT vs CALL SYMPUTX

Call Symput: Use CALL SYMPUT is you need to assign a data step value to a macro variable. Syntax: Call Symput (“Macro variable”, character value) The first argument to the Symput routine is the name of the macro variable to be assigned to the value from the second argument. The second argument is the character value that will be assigned to the macro variable. The second argument need to be always a character value or if a numeric value is to be used it should convert first into character variable before assigning it to macro variable. It may lead to problems, if you don’t do the conversion from numeric to character. In this case, SAS automatically converts numeric value of the variable to character value before assigning it to macro variable and prints a message in the LOG saying that conversion happened. See the example: data _null_; count= 1978 ; call symput('count',count); run; %put &count; 19 data _null_; 20 count=1978; 21 call symput('count',count); 22 run; ...

How to determine the executing program name and path programatically

Sometimes, we need to keep the name and path of the executing program in the FOOTNOTE of the generated table or listings. I have always created a macro variable using the %let statement and, then I called the Macro variable in the footnote statement to get the name of the program. Eventhough it is simple.. it may not be suitable when we write application which need to self document... Here is another technique which can be used to retrieve the pathname and filename (last executed) ..... To get the last opened filename: proc sql noprint; select scan (xpath,-1, ' \ ') into :progname from sashelp.vextfl where upcase( xpath ) like '%.SAS' ; quit ; %put &progname; result: filename.sas or data _null_; set sashelp.vextfl( where = ( upcase ( xpath ) like '%.SAS' )); call symput ( 'program' , scan ( xpath , - 1 , '\' )); run ; %put &program; result: filename.sas To get path name ... then .. use the following code; ...

How to check if the File is exist or not in SAS

How to check if the File is exist or not in SAS: Guys… Let me try explaining how to check if the file exist in the library or directory using SAS. Here I am writing a macro to check if the file exist in the directory or not. Here is the way to check it… % macro check(dir= ) ; %if %sysfunc ( fileexist (&dir)) %then %do; % put File Exists ; % end ; %else %do ; %put File doesn’t exist.; % end ; % mend ; %check (dir=" C:\Documents and Settings\sannapareddy\Desktop\Holidays 2009.docx" ); %sysfunc option empowers me to use the same Data step functions outside the Data step. Almost all of the Data step functions are available to use outside the data step if we use %sysfunc. fileexist option, verifies the existence of an external file. It can also verifies the SAS library. Here is another simple technique to check..... data _null_ ; x= filexist( 'C:\Documents and Settings\sannapareddy\Desktop\Holidays 2009.docx' ); call...