Posts

Showing posts from July, 2009

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