BookmarkSubscribeRSS Feed
RTelang
Fluorite | Level 6

 A macro that identifies any variables either character or numeric – for which all of the observations are missing values. When this occurs, a warning message is output to the SAS log.

 

%macro vtype(dsname=, varname=, outputflag=);
%if %sysfunc(exist(&dsname)) %then %do;
%let dsid = %sysfunc(open(&dsname));
%let varnum = %sysfunc(varnum(&dsid,&varname));
%let vartyp = %sysfunc(vartype(&dsid,&varnum));
%if &vartyp = C %then %do;
%let &outputflag=&vartyp;
%put &varname=character;
%end;
%else %if &vartyp = N %then %do;
%let &outputflag=&vartyp;
%put &varname=numeric;
%end;
%end;
%else %put "DSNAME parameter is invalid Please pass appropriate values.";
%mend vtype;

 

 

this my code how can i change it according to my requirment?

4 REPLIES 4
And
Calcite | Level 5 And
Calcite | Level 5

Hello,

 

You can check for missing values using proc sql:

proc sql noprint;
select max(&varname) into :max_value from &dsname;
quit;

and afterwards just check the value of the newly created macro variable:

 

%if &max_value= or  &max_value=. %then %do; %put &varname has only missing values;%end;

 

RTelang
Fluorite | Level 6
@And thanks my prog runs well, but y aren't u using count instead of max??
RTelang
Fluorite | Level 6
@And how do i incorporate ur code in my code? am having errors can u give all together??
Astounding
PROC Star

It's extremely unlikely that missing values could cause a problem.  Here are two other situations that are more likely candidates.

 

(1) Even if DSNAME does not exist, your macro still attempts to extract VARNUM to identify the position of VARNAME.

 

(2) If DSNAME exists but does not contain VARNAME, your macro still attempts to extract whether VARNAME is numeric or character.

 

I would be shocked if SAS even examines the values of VARNAME.  The problem almost certainly lies elsewhere.

 

Good luck.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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