turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- using first. = . repedetively

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-03-2012 04:02 PM

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

Accepted Solutions

Solution

02-03-2012
06:00 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-03-2012 06:00 PM

by year type store ;

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

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-03-2012 04:08 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-03-2012 04:15 PM

** **

**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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-03-2012 04:20 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-03-2012 04:22 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-03-2012 04:24 PM

yes

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-03-2012 04:26 PM

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-03-2012 10:28 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-03-2012 10:44 PM

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

Solution

02-03-2012
06:00 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-03-2012 06:00 PM

by year type store ;

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-03-2012 07:01 PM

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.