BookmarkSubscribeRSS Feed
Filipvdr
Pyrite | Level 9
Is it possible to delete - drop columns if there isn't any value in for each row of the dataset?
5 REPLIES 5
data_null__
Jade | Level 19
> Is it possible to delete - drop columns if there
> isn't any value in for each row of the dataset?

Yes but you have to figure out what columns contain all missing values.

Here is one method.

[pre]
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;
[/pre]
Filipvdr
Pyrite | Level 9
ok that works quite nice! thanks a lot.

Is there something similar like: if this variable has always the same value ( you don't know the value up front)
data_null__
Jade | Level 19
[pre]
data have;
missing a b;
input name$ a b c d e;
*keep name a;
cards;
x 2 3 . . 7
y . 3 3 . 7
z . 3 . . 7
p . 3 . b 7
q . 3 . . 7
;;;;
run;
proc print;
run;


ods select nlevels;
ods output nlevels=nlevels;
proc freq levels;
run;
ods output close;

data nlevels;
/*NNonMissLevels will not exist when there are no*/
/*variables with missing values*/
retain NNonMissLevels 1;
set nlevels;
run;
proc print;
run;
%let oneLevel=;
proc sql noprint;
select tableVar into :oneLevel separated by ' '
from Nlevels where NLevels eq 1 and NNonMissLevels eq 1;
quit;
run;
%let oneLevel = %sysfunc(IFC(&oneLevel eq,%str( ),drop=&oneLevel));
%put NOTE: oneLevel=&oneLevel;

proc report data=have(&oneLevel) nowd;
run;
[/pre]
Filipvdr
Pyrite | Level 9
ok thanks but i'm bumping into a problem now

this is what i want to have: clicking on id gives me outputdata but this data can differ according to the id

Stored Process 2 handles the id and gives the output
1 - want to get rid of columns where all missings (your first piece of code)
2 - want go place a header text where all rows have the same value (your 2nd piece of code)

when i run these codes after each other in my STP it gives the following error:

NOTE: ALLMISS=drop=PmProcedure WaferId MeasKey sWaferId sNumberOfSites aDieNumber Thick_2 Thick_3 Sum_1 Refract_1 Refract_2
201 +

202 +

203 +/* added */

204 +proc print; run;

NOTE: There were 37 observations read from the data set WORK.NLEVELS.
NOTE: The PROCEDURE PRINT printed pages 6-7.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds


204 !+

205 +ods select nlevels;

206 +ods output nlevels=nlevels;

207 +proc freq levels; run;

ERROR: You cannot open WORK.NLEVELS.DATA for output access with member-level control because WORK.NLEVELS.DATA is in use by you in resource environment FREQ (223).
NOTE: The SAS System stopped processing this step because of errors.
NOTE: SAS set option OBS=0 and will continue to check statements. This may cause NOTE: No observations in data set.
NOTE: There were 37 observations read from the data set WORK.NLEVELS.
NOTE: The PROCEDURE FREQ printed page 8.
NOTE: PROCEDURE FREQ used (Total process time):
data_null__
Jade | Level 19
I don't know about stored processes. You might try ODS OUTPUT CLOSE or a different data set name NLEVELS1 and NLEVELS2.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1425 views
  • 0 likes
  • 2 in conversation