I have 3 first. criteria to use, but I must use ot on 14 different variables... is there a easy way to do this
if first.YEAR then price_GR=.;
if first.Type then price_GR=.;
if first.Store then price_GR=.;
I have 14 different price_GR=.; (eg. UN_GR, GDP_GR, etc.)
Cant have 14 series of the first.YEAR, first.Type and first.Store .. Is there a easy way to make them repedetive rather than type each out? thanks
by year type store ;
if first.store then call missing (UN_GR, GDP_GR, etc) ;
I'm not sure what you are trying to do. You can always specify them as:
if first.YEAR then do;
price_GR=.;
etc.
etc.
end;
if first.Type then do;
etc.
etc.
end;
etc.
You could also load your data into an array and, rather than have 14 statements, just refer to the variables in the array.
Not sure if this is what you are looking for. Regards, Udo
proc sort data=sashelp.class out=have;
by sex age;
run;
data want;
set have;
if first.sex then call missing(sex,age,height,weight);
if first.age then call missing(sex,age,height,weight);
by sex age;
run;
Let me try to explain it better:
Is there better way to write this?
if first.YEAR then price_GR=.;
if first.Type then price_GR=.;
if first.Store then price_GR=.;
if first.YEAR then UN_GR=.;
if first.Type then UN_GR=.;
if first.Store then UN_GR=.;
if first.YEAR then GDP_GR=.;
if first.Type then GDP_GR=.;
if first.Store then GDP_GR=.;
and so on 14 times with 14 different VARS_GR.... Thanks
Do those variables already exist and you just want them reset to missing?
yes
Here is an example of how you could do it for, say, all numeric variables:
proc sort data=sashelp.class out=test;
by age;
run;
data want;
set test;
array vars _numeric_;
by age;
if first.age then do over vars;
call missing(vars);
end;
run;
@ART
DO OVER?!
You definitely started with SAS some years ago. I believe DO OVER was already marked as "obsolete" in SAS V6 :smileylaugh:
In modern SAS you could write it with no explicit loop at all:
call missing(of _numeric_);
Patrick,
Yes, I started with SAS a long time ago. In fact, before it became a company!
However, I still like using do over and don't know why they stopped including it in the documentation.
Yes, in this case, your suggestion is all that would be needed. But not quite so easy for other assignments. Unfortunately, they never included a similar call assign (e.g., call (assign,3, of _numeric_);
by year type store ;
if first.store then call missing (UN_GR, GDP_GR, etc) ;
As Howles has said already you do not need to test all of the higher level variables in the sort order. If it the first for higher level term it also the first for the lower level term, by the definition of how FIRST. is calculated. So it you just reset on the first. for the lowest level term it will also reset at the first for all of the higher level terms.
To reset a number of variables to missing use the call missing statement.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.