BookmarkSubscribeRSS Feed
8 REPLIES 8
PaigeMiller
Diamond | Level 26

Once a variable is declared to be in an array, it is in the array, I don't think you can remove it during the same data step.

 

Perhaps you could explain the bigger picture, what you are doing, why you are doing it, what removing from array really means, etc. ?

--
Paige Miller
lovecoding
Calcite | Level 5
From the dataset keep only those variables that are not missing in all observations. 

data temp;

input var1-var6;
	
datalines;
	1 2 3 4 5 6
	. 1 2 3 4 6
	. . 2 0 . 6
	4 5 6 7 8 6
	1 . 3 4 . 6
;
run;
yabwon
Onyx | Level 15
data temp;
input var1-var6;
datalines;
	1 2 3 4 5 6
	. 1 2 3 4 6
	. . 2 0 . 6
	4 5 6 7 8 6
	1 . 3 4 . 6
;
run;

data _null_;
set temp end=EOF;
array v var1-var6;
array N null1-null6;

do over v;
  if missing(v) then n=1;
end;

if EOF then
  do;
    call execute("data new_temp; set temp(drop=");
    do over v;
      if n then call execute(vname(v));
    end;
    call execute("); run;");
  end;
run;
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Davit198
Calcite | Level 5
Does not corectly worke,becouse you take only last row to determine missings
yabwon
Onyx | Level 15

Right, should be:

if missing(v) then n+1;

instead `n=1`.

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



PaigeMiller
Diamond | Level 26

So this really has nothing to do with arrays? Just remove a variable from the data set (not from the array) if it has a missing?

 

proc summary data=temp;
    var var1-var6;
    output out=stats nmiss=;
run;
proc transpose data=stats(drop=_type_ _freq_) out=stats1;
run;    
proc sql noprint;
    select distinct _name_ into :names separated by ' ' from stats1 where col1=0;
quit;
data want;
    set temp(keep=&names);
run;
--
Paige Miller
AMSAS
SAS Super FREQ

Can you provide more details this is somewhat vague


Ksharp
Super User
data temp;
input var1-var6;
datalines;
	1 2 3 4 5 6
	. 1 2 3 4 6
	. . 2 0 . 6
	4 5 6 7 8 6
	1 . 3 4 . 6
;
run;

ods select none;
ods output nlevels=nlevels;
proc freq data=temp nlevels;
table _all_;
run;
ods select all;

proc sql noprint;
select TableVar into :keep separated by ' ' from nlevels where NMissLevels=0;
quit;

data want;
 set temp;
 keep &keep.;
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 1924 views
  • 5 likes
  • 6 in conversation