DATA Step, Macro, Functions and more

How to create dummy data for reporting

Reply
Regular Contributor
Posts: 161

How to create dummy data for reporting

I want to create a line which should say if i do not have a record named 'Missing variable ' i need to create it and assign values as 0 and if present leave as it is.

 

Can anyone help me in this.

 

 

 

Trusted Advisor
Posts: 1,933

Re: How to create dummy data for reporting

Without more specific information, its impossible to give you the exact code

 

However, the steps would be:

 

  1. Search for record named "missing variable"
  2. If not found, create the record with values of 0
Valued Guide
Posts: 860

Re: How to create dummy data for reporting

Give an example of the data you have and what you want.  I'm having trouble imagining:  looking for 'missing variable' and adding record with value of 0.

Frequent Contributor
Posts: 130

Re: How to create dummy data for reporting

As others have mentioned, it would be a lot easier if you provided some example data and what you are looking the output to be.  Just guessing here and thinking what I would do to search for a variable within a data set, I came up with the following.  Not sure if this is what you're looking for or not.

 

data have1;
input ID$ Value;
datalines;
1 100
2 200
;
run;

data have2;
input ID$;
datalines;
1
2
;
run;

options mprint symbolgen mlogic;
%macro missing(lib,data,var);
proc sql noprint;
select name into: Variables separated by ","
from sashelp.vcolumn
where libname="&lib" AND memname="&data";
quit;

data _NULL_;
check=find("&Variables","&var");
call symput("check",check);
run;

%if &check=0 %then %do;
	data &lib..&data;
	set &lib..&data;
	&var=0;
	run;
%end;
%mend;

%missing(WORK,HAVE1,Value)
%missing(WORK,HAVE2,Value);
Trusted Advisor
Posts: 1,118

Re: How to create dummy data for reporting

I am not familiar with the concept of a "record name" either, but as people have already started guessing, I would like to suggest the following as a draft you could start with (under certain assumptions):

data have;
length record_name $20;
input record_name a b c;
cards;
abc    3 1 4
defghi 1 5 9
jklm   2 6 5
;

data want;
set have end=last;
array numvar[*] a--c; /* replace a--c by the list of variables you want to set to zero */
output;
missvarflag+(record_name='Missing variable'); /* replace "record_name=..." by your criterion for a record named ... */
if last & ~missvarflag then do;
  record_name='Missing variable'; /* see above */
  do _n_=1 to dim(numvar);
    numvar[_n_]=0;
  end;
  output;
end;
drop missvarflag;
run; 

 

Ask a Question
Discussion stats
  • 4 replies
  • 304 views
  • 0 likes
  • 5 in conversation