BookmarkSubscribeRSS Feed
TM
Calcite | Level 5 TM
Calcite | Level 5

Hi. I have a question that my knowledge of datasteps and arrays can't really handle.

I have some data of the form:

Iden     Var1     Var2     Var3     Var4

1            x          y         

2                             

3                                    y

4                         x          z

What i hope to make clear is that i have different variables, named anumabb2 to anumabb34, that contain non-numeric text.

What i wan't to delete is the row with iden 2, because all that exact one has all empty variable slots.

I hope it makes sense, and i'm thinking it has a simple solution that im too high on coffee to find for myself!

Thanks

TM

4 REPLIES 4
art297
Opal | Level 21

Tim,  How about something like:

data want;

  set have;

  array cvars(*) var1--var4;

  if not(cmiss(of cvars(*)) eq dim(cvars));

run;

MikeZdeb
Rhodochrosite | Level 12

Hi ... here's another idea. 

data new;

set old;

if ^missing(cats(of anumabb2-anumabb34));

run;

A generic approac to this question is shown below. 

The OPTIONS MISSING=' ' is needed if there are

any numeric variables in your data set since the CATS function will  add

a period to the concatenated string of values if the default value of

a period is used.

options missing = ' ';

data new;

set old;

if ^missing(cats(of _all_));

run;

options missing = '.';

jonam
Calcite | Level 5

data INPUT;

iden=1;

var1='x';

var2='y';

var3='';

var4='';

output;

iden=2;

var1='';

var2='';

var3='';

var4='';

output;

iden=3;

var1='';

var2='';

var3='u';

var4='';

output;

iden=4;

var1='';

var2='';

var3='x';

var4='z';

output;

iden=1;

var1='';

var2='y';

var3='';

var4='';

output;

run;

proc sql;

select COMPRESS(name)||" is not null" into :COND SEPARATED BY ' OR '

from sashelp.vcolumn

where memname='TEST' AND TYPE='char'

     AND LIBNAME='WORK';

QUIT;

%PUT &COND.;

DATA WANT;

SET INPUT;

WHERE &COND.;

RUN;

Step 1: i'm selecting all the variables that are character as per the requirement into a macro variable . (Using dictionary)

Step 2: using the macro to be used as my where clause condition.  Though it looks like two steps, the first steps doesn't access data but dictionary, hence it  doesn't take time.

I'm using where clause instead of if to improve the performance.   but it works. 

Ksharp
Super User

Art has already given your answer.

data temp;
infile datalines truncover;
input (Iden     Var1     Var2     Var3     Var4 ) ($) ;
datalines;
1            x          y         
2                             
3                                    y
4                         x          z
;
run;
%global nvar list;
proc sql noprint;
 select name ,count(name) 
   into : list separated by ',', : nvar
  from dictionary.columns
   where libname='WORK' and memname='TEMP' and name like 'Var%';
quit;
%put &nvar &list;

data temp;
 set temp;
 if cmiss(of &list) eq &nvar then delete;
run;

Ksharp

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 4235 views
  • 0 likes
  • 5 in conversation