From: bcubeb3 on
Problem Description:
I would like to automize this program so that it looks at every
variable (column) and first check whether the column is
numerical and execute two lines of code:
If Salary ne . then filled4 = 1;
If Salary eq . then filled4 = 0;

or if the column is of a string type then execute these two lines of
code:
If Team ne '' then filled1 = 1;
If Team eq '' then filled1 = 0;

With the column variable be any varying number, some data sets have 7
some have 50 columns,
and the filled1 to filledn will the number of columns generated for n
column field types. I am not sure if there is a general way
to do my program. But if there is, this will make it much easier for
me. I have to automize for the rest of this program but as of
et there is obvious way to do it for the rest as of now, but the above
is an idea of starting to make my simple program general and
powerful.

Best,
Barry Barrios

/**************************Below is the
program***********************************************/
data Sample2;
set Sample;
If Team ne '' then filled1 = 1;
If Team eq '' then filled1 = 0;
If Player ne '' then filled2 = 1;
If Player eq '' then filled2= 0;
If Experience ne . then filled3 =1;
If Experience eq . then filled3 = 0;
If Salary ne . then filled4 = 1;
If Salary eq . then filled4 = 0;
filled = filled1 + filled2 + filled3 + filled4;
ratio = filled/4.0;
run;

data Sample2;
set Sample2;
drop filled1 filled2 filled3 filled4;
run;
data Sample2;
set Sample2;
if filled = 0 then Group = 'G1';
if filled = 1 then Group = 'G2';
if filled = 2 then Group = 'G3';
if filled = 3 then Group = 'G4';
if filled = 4 then Group = 'G5';
run;

proc sort data = Sample2;
by Group;
run;

proc summary data = Sample2;
by Group;
freq filled;
output out = Sample_Out;
run;

proc summary data = Sample2;
freq filled;
output out = Sample_Out2;
run;
data Sample_Out;
set Sample_Out;
drop _TYPE_;
rename _FREQ_ = Num_Records;
run;

data Sample_Out2;
set Sample_Out2;
drop _TYPE_;
rename _FREQ_ = Total_Records;
run;

data Output;
IF _N_ = 1 THEN SET Sample_Out2;
set Sample_Out;
run;

data Output;
set Output;
Percent_Of_Records = 100*(Num_Records/Total_Records);
drop Total_Records Num_Records;
run;
/*****************************END OF PROGRAM
******************************/
From: data _null_; on
On Jun 9, 8:29 am, bcubeb3 <barry.brian.barr...(a)gmail.com> wrote:
> Problem Description:
>   I would like to automize this program so that it looks at every
> variable (column) and first check whether the column is
> numerical and execute two lines of code:
>     If Salary ne . then filled4 = 1;
>     If Salary eq . then filled4 = 0;
>
> or if the column is of a string type then execute these two lines of
> code:
>    If Team ne '' then filled1 = 1;
>     If Team eq '' then filled1 = 0;
>
> With the column variable be any varying number, some data sets have 7
> some have 50 columns,
> and the filled1 to filledn will the number of columns generated for n
> column field types. I am not sure if there is a general way
> to do my program. But if there is, this will make it much easier for
> me. I have to automize for the rest of this program but as of
> et there is obvious way to do it for the rest as of now, but the above
> is an idea of starting to make my simple program general and
> powerful.
>
> Best,
> Barry Barrios
>
> /**************************Below is the
> program***********************************************/
> data Sample2;
>     set Sample;
>     If Team ne '' then filled1 = 1;
>     If Team eq '' then filled1 = 0;
>     If Player ne '' then filled2 = 1;
>     If Player eq '' then filled2= 0;
>     If Experience ne . then filled3 =1;
>     If Experience eq . then filled3 = 0;
>     If Salary ne . then filled4 = 1;
>     If Salary eq . then filled4 = 0;
>     filled = filled1 + filled2 + filled3 + filled4;
>     ratio = filled/4.0;
> run;
>
> data Sample2;
>     set Sample2;
>     drop filled1 filled2 filled3 filled4;
> run;
> data Sample2;
>     set Sample2;
> if filled = 0 then Group = 'G1';
> if filled = 1 then Group = 'G2';
> if filled = 2 then Group = 'G3';
> if filled = 3 then Group = 'G4';
> if filled = 4 then Group = 'G5';
> run;
>
> proc sort data = Sample2;
>     by Group;
> run;
>
> proc summary data = Sample2;
>     by Group;
>     freq filled;
>     output  out = Sample_Out;
>    run;
>
>    proc summary data = Sample2;
>     freq filled;
>     output  out = Sample_Out2;
>    run;
> data Sample_Out;
>        set Sample_Out;
>        drop _TYPE_;
>        rename _FREQ_ = Num_Records;
> run;
>
> data Sample_Out2;
>        set Sample_Out2;
>        drop _TYPE_;
>        rename _FREQ_ = Total_Records;
> run;
>
> data Output;
>     IF _N_ = 1 THEN SET Sample_Out2;
>     set Sample_Out;
> run;
>
> data Output;
>     set Output;
>     Percent_Of_Records = 100*(Num_Records/Total_Records);
>     drop Total_Records Num_Records;
> run;
> /*****************************END OF PROGRAM
> ******************************/

Use two arrays one for Char and the other for numeric.

set ....;
array _c[*] _character_;
array _n[*] _numeric_;

do _n_ = 1 to dim(_c);
if...
end;
do _n_ = 1 to dim(_n);
if ...
end;

If there are no variables of one or the other type you will need to
omit the array reference or use a little trick to insure at least one
variable of each type.

See SAS documentation regarding the "SAS Variable Lists".
http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer..htm#/documentation/cdl/en/lrcon/62955/HTML/default/a000695105.htm