OBS=0 then what do??

Reply
Frequent Contributor
Posts: 89

OBS=0 then what do??

hai all,

          I would like to know how to treat data set with 0 observation.Here my data set has 0  observation.Weather the observation become zero then i need to put the column value as 0.How it possible??

Thanks

Krishna

Contributor
Posts: 23

Re: OBS=0 then what do??

Have you tried using proc contents on the dataset with an out= option?

proc contents data=InwardsDatasetName out=OutputDatasetName; run;

This will give you a dataset with a row for each variable and a column NOBS for the number of observations in the dataset.

Respected Advisor
Posts: 4,998

Re: OBS=0 then what do??

It sounds like you are trying to convert zero-observation data sets to one-observation data sets, but otherwise (if you started with more than zero observations) leave the data unchanged.  Here's one idea:

data want;

   if 0 then set have end=no_data;

   if no_data then do;

      array nums {*} _numeric_;

      do _n_=1 to dim(nums);

           nums{_n_}=0;

      end;

      output;

   end;

   set have;

   output;

run;

Good luck.

Frequent Contributor
Posts: 89

Re: OBS=0 then what do??

Hai thanks for the swift response..Smiley Happy

Also i need to know how to set a character value only to  the first column

Respected Advisor
Posts: 3,775

Re: OBS=0 then what do??

Use the MODIFY statement to add a single obs if there are none and you don't have to recreate the data.

data class;
   stop;
  
set sashelp.class;
   run;


data class;  
  
if eof then output;
  
stop;
  
if 0 then modify class end=eof;
   retain _char_ 'x' _numeric_ 0;
  
run;
proc print data=class;
   run;
Ask a Question
Discussion stats
  • 4 replies
  • 327 views
  • 6 likes
  • 4 in conversation