We all know that SAS has two kinds of library: permanent library and temporary WORK library. However, do you know that there are still two special permanent libraries?
USER:
When it exists, all datasets reference with a one level name will be written to the the permanent USER library instead of the temporary WORK library.
For the convenience of debugging, I suggest we can miss "WORK." when reference dataset.
Note: system option USER has the same effect.
LIBRARY:
In FMTSEARCH, there are ALWAYS two implicit format catalogs: WORK.FORMATS and LIBRARY.FORMATS. If they do not appear in FMTSEARCH= list, they will be searched at first.
Showing posts with label format. Show all posts
Showing posts with label format. Show all posts
Thursday, April 1, 2010
Monday, September 7, 2009
PUT function vs. INPUT function
What about the relationship between them?
In my opinion, INPUT function is the inverse process of PUT function.
PUT function: convert the variable value to a character string
INPUT function: convert a character string to the variable value
In my opinion, INPUT function is the inverse process of PUT function.
PUT function: convert the variable value to a character string
INPUT function: convert a character string to the variable value
Thursday, January 22, 2009
How to check format exist?
The popular method to identify the format is using dictionary tables (catalogs and formats).
What is the difference between them?
If you check the existence only from the format searchpath, dictionary.formats is the key. Otherwise, you can get ALL formats using dictionary.catalogs.
proc sql;
select libname, memname, objname
from dictionary.catalogs
where objtype contains 'FORMAT' and objname = 'FMTNAME' ;
proc sql;
select libname, memname, objname
from dictionary.formats
where objname = 'FMTNAME' ;
quit;
What is the difference between them?
If you check the existence only from the format searchpath, dictionary.formats is the key. Otherwise, you can get ALL formats using dictionary.catalogs.
proc sql;
select libname, memname, objname
from dictionary.catalogs
where objtype contains 'FORMAT' and objname = 'FMTNAME' ;
proc sql;
select libname, memname, objname
from dictionary.formats
where objname = 'FMTNAME' ;
quit;
Tuesday, December 9, 2008
How to sort dataset with format?
Every SAS programmer must be familiar with Proc SORT. Every time we merge multiple datasets, do group-by processing, etc. we have to sort the dataset by key variables.
In many procs, Format statement can function partly as group-by processing, e.g. Proc MEANS, Proc REPORT etc.
However, different from the procs above, Format statement dose not do group-by processing in Proc SORT.
The Format statement in Proc SORT ONLY assign the format to the variable in output dataset.
Generally, we create a new variable based on the format and then sort the new variable using Proc SORT.
With Proc SQL, we can do the same operations in one step. :)
Sample code:
In many procs, Format statement can function partly as group-by processing, e.g. Proc MEANS, Proc REPORT etc.
However, different from the procs above, Format statement dose not do group-by processing in Proc SORT.
The Format statement in Proc SORT ONLY assign the format to the variable in output dataset.
Generally, we create a new variable based on the format and then sort the new variable using Proc SORT.
With Proc SQL, we can do the same operations in one step. :)
Sample code:
proc format;
value $sex
'M' = '1'
'F' = '2';
run;
* Format statement does not work in Proc SORT;
proc sort data=sashelp.class out=sortfail;
format sex $sex.;
by sex;
run;
* With Proc SQL, we can sort the dataset with format
in one step;
proc sql;
create table sortok as
select * from sashelp.class
order by put(sex, $sex.);
quit;
* More steps with "by vars NOTSORTED";
Subscribe to:
Posts (Atom)