BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
podarum
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
Howles
Quartz | Level 8

by year type store ;

if first.store then call missing (UN_GR, GDP_GR, etc) ;

View solution in original post

10 REPLIES 10
art297
Opal | Level 21

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.

udo_sas
SAS Employee

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;

podarum
Quartz | Level 8

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

art297
Opal | Level 21

Do those variables already exist and you just want them reset to missing?

podarum
Quartz | Level 8

yes

art297
Opal | Level 21

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;

Patrick
Opal | Level 21

@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_); 

art297
Opal | Level 21

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_);

Howles
Quartz | Level 8

by year type store ;

if first.store then call missing (UN_GR, GDP_GR, etc) ;

Tom
Super User Tom
Super User

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 892 views
  • 0 likes
  • 6 in conversation