From: Gerhard Hellriegel on
for sure you can check a dataset variable, but it is important to know
what you REALLY mean with that.
Checking a dataset for existance or 0-obs is one thing, but a variable?
That might be different for each obs? What means missing? Missing on all
obs? Missing on one obs? Or is the question, if a variable exists or not?
Not clear to me...
If you mean "missing on all obs", you might summarize in a retained
variable and check that at end.

data _null_;
set xy end=eof (keep=var);
retain check;
check=sum(check,var);
if check>. then do;
put "not all VAR missing!";
stop;
end;
if eof and check=. then do;
put "all VAR missing";
end;
run;

If var is a char variable, you might concatenate that in a retained
variable and check if it is still "" at end.

....and what means "print that variable in proc report"? Print nothing in
proc report?

Gerhard




On Mon, 8 Mar 2010 09:56:18 -0800, SAS_learner <proccontents(a)GMAIL.COM>
wrote:

>Hello all,
>
>I can see and check if a dataset is missing or not using something like
>this,
>
>%let dsid=%sysfunc(open(work.test,in));
>%let nobs=%sysfunc(attrn(&dsid,nobs));
>%if &dsid > 0 %then %let rc=%sysfunc(close(&dsid));
>
>if there something similar that to check to see if there is a Variable
>present is Null or not and to Print that variable in Proc Report ??
>
>Thanks
>SL
From: SAS_learner on
Hello Gerhard,
Thanks for Quick response,may be example would more clear to what I am
asking. I am playing with Data_null_ suggestion dynamically running proc
report(See the code below). Here I know for sure that Temp and N_temp are
missing. But is there a way I can check to see if these variables are
missing ( does not have any values) so I can avoid them putting them in
Column statement and in the define statement. (May be I am looking at
wrong angle of doing this )



data class;
set sashelp.class;
Temp = "" ;
N_temp = . ;
label
Age='Age of Subject'
Height='Height of Subject'
Name='name of the subject'
;
format age f8. Height f9.1;
informat age 10. name 20.;
retain Comment 'This is long comment text that needs to be flowed';
run;

%macro
report
(
data = , /* [R] data */
columns = , /* [O] Column statement may be blank &VARS is used */
vars = , /* [R] so we don't have to figure out the name
of the vars in COLUMNS */
format = , /* [O] to change formats at runtime */
label = , /* [O] to change labels at runtime */
width = , /* [O] to specify field width */
flow = /* [O] flow option */
/* you could do the rest ORDER GROUP RIGHT LEFT CENTER etc.*/
);

%if %superQ(columns) eq %then %let columns=&vars;

proc transpose data=&data(obs=0) out=vars(index=(_name_));
var &vars;
copy &vars;
%sysfunc(ifc(%sysevalF(%superq(format) ne,boolean),%nrstr(format
&format;),%str()));
%sysfunc(ifc(%sysevalF(%superq(label) ne,boolean), %nrstr(label
&label;),%str()));
run;
proc sql noprint;
select _name_ into :vars SEPARATED ' '
from vars;
quit;
data flow;
format &vars;
retain &flow _dummy_ 1;
output;
stop;
call missing(of _all_);
run;
proc transpose data=flow
out=flow(rename=(col1=_FLOW_) where=(_name_ ne '_dummy_')
index=(_name_))
;
var _all_;
run;
data width;
format &vars;
retain &width;
retain _dummy_ 0;
output;
call missing(of _all_);
run;
proc transpose data=width
out=width(rename=(col1=_WIDTH_) where=(_name_ ne '_dummy_')
index=(_name_))
;
var _all_;
run;
data vars;
retain _DATA_ "&data";
set vars;
set width key=_name_/unique;
if _error_ ne 0 then do;
call missing(_width_);
_error_=0;
end;
set flow key=_name_/unique;
if _error_ ne 0 then do;
call missing(_flow_);
_error_=0;
end;
length _FORMAT_ $32;
_format_ = vformatX(_name_);

run;
proc print;
run;
data _null_;
if _n_ eq 1 then set vars(keep=_data_);
length ddname $8 filevar $128;
rc = filename(ddname,,'TEMP');
filevar=pathname(ddname);
rc = filename(ddname);
putlog filevar=;
file dummy filevar=filevar;
put 'Proc Report nowd list headline headskip data=' _data_ ';';
put +3 'Columns ' "(&columns)" ';';
do until(eof);
set vars end=eof;
put +3 'define ' _name_ ' / display ' @ ;
if not missing(_width_) then put 'width=' _width_ @;
if _flow_ then put ' FLOW ' @;
if not missing(_format_) then put 'FORMAT=' _format_ @;
if not missing(_label_) then put _label_ :$quote258.;
put +(-1) ';';
end;
put +3 'Run;';
call execute(cats('%inc',quote(strip(filevar)),';'));
stop;
run;
%mend report;
options mprint=1;
%report
(
data = class,
vars = Age Height Name Comment Temp N_temp,
columns = %nrstr('--' &vars),
format = Height f10.1,
label = age="Student's age",
width = comment 20 age 10,
flow = comment
);
From: "Data _null_;" on
On 3/8/10, Mike Zdeb <msz03(a)albany.edu> wrote:
> hi ... courtesy of stuff in a data _null_ posting a couple weeks ago

Actually if you just want to know which variables have all missing
values you can get all that info from the LEVELS option of PROC FREQ.
This could be added to a macro to create a drop list.

data have;
missing a b;
input name$ a b c d e;
*keep name a;
cards;
x 2 . . . .
y . . 3 . .
z . a . . .
p . . . b .
q . . . . .
;;;;
run;
proc print;
run;


proc format; *To speedup PROC FREQ;
value allmiss ._-.z=. other=1;
value $allmiss ' '=' ' other='1';
run;

ods select nlevels;
ods output nlevels=nlevels;
proc freq levels;
format _character_ $allmiss. _numeric_ allmiss.;
run;
ods output close;

data nlevels;
/*NNonMissLevels will not exist when there are no*/
/*variables with missing values*/
retain NNonMissLevels -1;
set nlevels;
run;

%let allMiss=;
proc sql noprint;
select tableVar into :allmiss separated by ' '
from Nlevels where NNonMissLevels = 0;
quit;
run;
%let allmiss = %sysfunc(IFC(&allmiss eq,%str( ),drop=&allmiss));
%put NOTE: ALLMISS=&allMiss;

proc report data=have(&allmiss) nowd;
run;
From: Jim Groeneveld on
Hi SL,

I would do a PROC FREQ (to an output dataset) on such a variable to see the
available values. If just one value is available and it is missing the
variable name might be removed from a list of variables (in a macro
variable) to present.

I used a strategy like that in a macro to automatically delete all variables
with missing values only from any dataset: DropMV.sas, in:
http://jim.groeneveld.eu.tf/software/SASmacro/DropMV.zip

Regards - Jim.
--
Jim Groeneveld, Netherlands
Statistician, SAS consultant
http://jim.groeneveld.eu.tf


On Mon, 8 Mar 2010 09:56:18 -0800, SAS_learner <proccontents(a)GMAIL.COM> wrote:

>Hello all,
>
>I can see and check if a dataset is missing or not using something like
>this,
>
>%let dsid=%sysfunc(open(work.test,in));
>%let nobs=%sysfunc(attrn(&dsid,nobs));
>%if &dsid > 0 %then %let rc=%sysfunc(close(&dsid));
>
>if there something similar that to check to see if there is a Variable
>present is Null or not and to Print that variable in Proc Report ??
>
>Thanks
>SL