Posts

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; ...

Dictionary Tables and SASHELP Views:

Image
Most of the SAS programmers think that the Metadata concepts (Dictionary tables and SASHELP views) are advanced SAS topics, in fact it is not. I tried here to explain the concept precise and clear…… Here, I will cover the following topics…… Introduction to SAS metadata How to see what’s in the tables How to use the tables, using several real-world examples Advantages What are Dictionary Tables 4 ? Dictionary tables are created and automatically maintained by SAS system at run time to store information related to SAS data libraries, SAS system options, SAS catalogs, and external files associated with the currently running SAS session. CATALOGS, COLUMNS, EXTFILES, INDEXES, MEMBERS, MACRO, OPTIONS, TABLES, TITLES, AND VIEW are these objects which provide detailed information about the SAS files. DICTIONARY tables are special read-only PROC SQL tables. They retrieve information about all the SAS data libraries, SAS data sets, SAS system options, and external files that are associat...

Even you can Use HASH and DOUBLE DASH: It’s that Simple……

In order to understand HASH and DOUBLE HASH concept in SAS you need to know about two different ranges of variables: 1) Numbered list: When a set of variables have the same prefix, and the rest of the name is a consecutive set of numbers, we can use a single dash (-) to refer to an entire range. Some exs.. are…. VAR1 VAR2 VAR3 VAR4 VAR5 Shortcut list you can use to access all 5 variables is VAR1-VAR5 COL1 COL2 COL3 COL4 COL5 COL6 COL7 Shortcut list you can use to access all 7 variables is COL1-COL7 2) Name range list: When you refer to a list of variables in the order in which they were defined in the SAS dataset, you can use a double dash (--) to refer to the entire range of variables in between them. Ex: VAR1 VAR2 VAR3 COUNT VAR4 COL1 VAR5 Shortcut list you can use to access all 7 variables (including COL1, which has different prefix name than others) is VAR1- -VAR5 The general rule you should always remember for dash and double dash is: Single dash is useful to access the consequent...

Renaming All Variables in a SAS Data Set Using the SASHELP VIEWS

*Create a temporary dataset... DSN; data dsn; a=1; b=2; c=3; d=4; e=5; f=6; run; % macro test(lib,dsn); */1)*/ data _null_; set sashelp.vtable(where=(libname=" &LIB " and memname= "&DSN" )); call symput( 'nvars', nvar); run; */2)*/ data dsn; set sashelp.vcolumn(where=(libname ="&LIB" and memname= "&DSN" )); call symput(cats( "var" ,_n_),name); run; */3)*/ proc datasets library =&LIB; modify &DSN; rename % do i = 1 % to &nvars; &&var&i=Rename_&&var&i. % end ; ; quit; run; % mend ; %test (WORK,DSN); After submitting the above program... the output looks like this.... Output: Rename_a Rename_b Rename_c Rename_d Rename_e Rename_f 1 2 3 4 5 6 Here is a way I know of.. to rename all the variables in the dataset; It can be done using the SASHELP views as follows: 1) The 1st step of the program determines the total number of variables inside the dataset with the help of SA...

Subscript or Superscript in the footers/titles of RTF output

Image
Wondering how to create a subscripts and superscipt in title or footnotes of the rtf output... here is a way to do it.... Execute the following program to get an Idea about how to keep SUBSCRIPTS and SUPERSCRIPTS in footnotes and titles of rtf output.. ************************************************************; data test ; length secnam $15; input sortord secnam $ pvalue; cards; 1 demog 0.8812 2 ae 0.7112 3 disposition 0.8112 4 medicalhistory 0.9112 ; run; ods listing close; ods rtf file = "Test output.rtf" style= rtfout ; ods escapechar = '\' ; proc report data = test missing split= "$" spacing=0 headline nowd; column sortord secnam pvalue ; define sortord / order noprint; define secnam / order flow "Demographics$Variable\{super a}" ; define pvalue / display flow "ANOVA$P-Value\{sub p}" ; run; ods rtf close; ods trace off; ods listing; *************************************************************; Variable\{super a}"; *Adds a...

%EVAL AND %SYSEVALF MACRO FUNCTIONS: GETTING TO KNOW THEM BETTER.

With the exception of %sysevalf function, integer arithmetic is the only way macro statements perform arithmetic calculations. Following are the few examples of macro statements performing integer arithmetic calculations: %let one= %eval (3+5); %let two= %eval (5*2); %let three= %eval (9/3); %let four= %eval (5/2); %put The value of one is &one; %put The value of two is &two; %put The value of three is &three; %put The value of four is & four; Open the Log file and see the results as follows: The value of one is 8 The value of two is 10 The value of three is 3 The value of four is 2 The value for macro variable four, should be 2.5, instead it shows only two. That happens because if we perform division on integers, integer arithmetic doesn’t take the fractional part into account. When we try to execute the integer arithmetic calculations of values with functional part, : %let last= %eval (5.0+3.0); /*INCORRECT*/ %EVAL function only supports integer arithmeti...

DEXPORT and DIMPORT: DISPLAY MANAGER commands used to IMPORT and EXPORT the Tab delimited (Excel and .CSV) files;

One of my favorite methods of exporting excel or .csv file is to use the ‘ DEXPORT ’ command-line command. This certainly reduces the amount of typing required to export the SAS dataset. Another interesting point is DEXPORT command works fine in UNIX and PC .   Syntax: dm “ DEXPORT libref.dsn 'filename.xls ' replace ;   "libref" is a library , "dsn" is the name of a SAS data set, and "filename.xls" is the name of the tab delimited text file(excel) being created. If we don’t specify the Libname or it is work then the dataset ‘dsn’ from the WORK directory is exported in a excel format to a specified location. Replace option … replaces the file if it already exists.     Use DIMPORT command-line command to convert/import a tab delimited (excel or .csv etc) into a SAS dataset. Syntax: dm “DIMPORT ‘filename.csv’ exc" replace; DIMPORT command tells SAS to import or convert the tab delimited file (filename.csv) to a SAS dataset named ‘ex...