12-11-2015 10:05 AM
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.
12-11-2015 10:10 AM
Without more specific information, its impossible to give you the exact code
However, the steps would be:
12-11-2015 01:37 PM
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);
12-11-2015 02:30 PM
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;