Before SAS 9, we have to handle date/time values conditionaly if they are not in uniform style. Now, it becomes easy to input many different variations of date/time values using ANYDT* informats.
It is mainly used in PROC IMPORT, the Import Wizard, raw file input which have different styles of date/time values.
As to ANYDT* informats, notice the two points at below:
#1: There is no INVALID DATA message or set _ERROR_ to 1 if the input text cannot be interpreted. (SAS Note)
#2: A new system option DATESTYLE is introduced to determine the sequence of month, day, and year
Monday, September 14, 2009
Thursday, September 10, 2009
Check variable exist in DATA step run time
First off, there is NO way to know exactly which variable exist in DATA step run time.
We can check the variable existence before DATA step run time. The popular method is Macro technology with File I/O functions or Dictionary table.
How to avoid creating this variable if it does not exist and to get the formatted value of the variable if it exist.
Here ia another way:
We can check the variable existence before DATA step run time. The popular method is Macro technology with File I/O functions or Dictionary table.
How to avoid creating this variable if it does not exist and to get the formatted value of the variable if it exist.
Here ia another way:
* Sample;
data dummy;
set sashelp.class (obs=0);
run;
data test;
set sashelp.class;
if _n_ = 1 then do;
drop varexist dsid rc;
retain varexist;
dsid = open('dummy');
varexist = varnum(dsid, "name");
rc = close(dsid);
end;
length tmp $ 20;
if varexist then do;
tmp = vvaluex("name");
end;
else tmp = '';
run;
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, September 3, 2009
Macro variable in PROC SQL
There are two ways to store values of column in PROC SQL.
1. mv with separator, which store values of the rows into one mv
2. mv range, which store value of one row per mv
1. mv with separator, which store values of the rows into one mv
2. mv range, which store value of one row per mv
* Sample code;
proc sql;
select distinct sex, name
into:sex seperated by ' ', :name1-:name100
from sashelp.class;
%let num = &sqlobs;
quit;
%put Number: &sqlobs;
%put _global_;
Thursday, August 20, 2009
Short for style expression
With the power of ODS, we can specify the style elements for specific location, especially for reporting procedure like PROC PRINT, PROC REPORT, PROC TABULATE.
If the style expression is trivial and long, it will be boring to apply same style expression to many reports at one time.
For example:
To avoid typing the same expression again and again, we can customize style using PROC TEMPLATE.
The report above can be converted to:
If the style expression is trivial and long, it will be boring to apply same style expression to many reports at one time.
For example:
ods html file="style.html";
proc report data=sashelp.class nowd;
column name age;
define name/display
style(header)=[just=l
foreground=red
cellwidth=2cm];
define age / display ;
run;
ods html close;
To avoid typing the same expression again and again, we can customize style using PROC TEMPLATE.
The report above can be converted to:
proc template;
define style styles.mystyle;
parent=default;
style header1 from header /
foreground=red
width=2cm
textalign=left;
end;
run;
ods html file="style2.html" style=mystyle;
proc report data=sashelp.class nowd;
column name age;
define name / style(header) = header1;
define age / display ;
run;
ods html close;
Tuesday, August 18, 2009
Are you missing "missing option"?
Generally, SAS do not take missing value as a valid value, especially for class variable. That means there will be an implicit filter to delete all "missing" class, e.g. the class variable in Proc MEANS, PROC FREQ.
Likewise, missing values is not valid value for any group, order or across variable in Proc REPORT.
Likewise, missing values is not valid value for any group, order or across variable in Proc REPORT.
Tuesday, August 11, 2009
What ODS templates are in use?
Generally, procedure output will use table template and style template.
Below are the methods to identify them:
#1:
ODS TRACE statement can print what table template is in use.
#2:
Default style information is in SAS registry.
command "regedit" -> ODS -> DESTINATION -> "Selected Style" entry in specified destination
Below are the methods to identify them:
#1:
ODS TRACE statement can print what table template is in use.
#2:
Default style information is in SAS registry.
command "regedit" -> ODS -> DESTINATION -> "Selected Style" entry in specified destination
Subscribe to:
Posts (Atom)