@Jumboshrimps wrote:
Running this code generates a data set of all variables and an additional column "i", with the value "1" for each ob. This is where I got stuck in a previous attempt, I don't have the code from that job, so I can't remember how I resolved it.
Also, where in the code is it including only those with a value of "1", and/or excluding nulls?
Should I add an IF f[i] IS NOT NULL THEN
if f[i] then fields=catx(',',fields,vname(f[i]));
Thanx.
If I has 1 after that DO loop then there weren't any variables in the array! That because a normal DO loop like : DO I=1 to 5; .... END; will stop when I becomes larger then the upper bound. So if I ends you as 1 then there were zero variables in the array. You should see a message in the log to that effect.
WARNING: Defining an array with zero elements.
To your question the answer is NO.
First because the syntax is wrong.
IF f[i] IS NOT NULL THEN ...
Will not work in SAS code. If you do need to test if something is MISSING (what SQL means by the keyword NULL) in SAS code then use the MISSING() function.
Second because the test is already covered by the existing test when the variables are NUMERIC.
if f[i] then fields=catx(',',fields,vname(f[i]));
SAS will treat a number that is missing or zero as FALSE and any other value as TRUE.
Now if the variables are CHARACTER then you will want to change the test in the IF statement to reflect that fact. So perhaps something like
if left(f[i]) = '1' then fields=catx(',',fields,vname(f[i]));
Because otherwise SAS will first try to convert the character value into a number and then test if the number means TRUE or FALSE. You will get a message in the LOG when SAS does that type of automatic type conversion.
1759 data test;
1760 array x [2] $2 ;
1761 do i=1 to dim(x);
1762 if x[i] then put x[i]= 'TRUE';
1763 else put x[i]= 'FALSE';
1764 end;
1765 run;
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
1762:8
x1= FALSE
x2= FALSE
NOTE: The data set WORK.TEST has 1 observations and 3 variables.
... View more