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.
Without more specific information, its impossible to give you the exact code
However, the steps would be:
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.
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);
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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.