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
- /
- Base SAS Programming
- /
- how to divide observations by a fixed one

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
- Permalink
- Email to a Friend
- Report Inappropriate Content

07-02-2008 04:53 AM

Hi,

I have a problem with a matrice. Could you help?

I have a table that looks like:

name year coefficient week_1 week_2 ...week_n

A Y_1

A Y_2

A Y_3

B Y_1

B Y_2

B Y_3

C Y_1

C Y_2

C Y_3

.

.

.

Z .

I would like to divide all week_i values of Names (A B C) by

week_i values of Name (Z) * coefficient(A B C).

Do you have an idea?

Can I use the lag function in a do-loop to keep the Z row in reference? because I try and it doesn't work...

Many thanks,

anais

I have a problem with a matrice. Could you help?

I have a table that looks like:

name year coefficient week_1 week_2 ...week_n

A Y_1

A Y_2

A Y_3

B Y_1

B Y_2

B Y_3

C Y_1

C Y_2

C Y_3

.

.

.

Z .

I would like to divide all week_i values of Names (A B C) by

week_i values of Name (Z) * coefficient(A B C).

Do you have an idea?

Can I use the lag function in a do-loop to keep the Z row in reference? because I try and it doesn't work...

Many thanks,

anais

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

Posted in reply to deleted_user

07-02-2008 05:19 AM

Hi Anaïs.

What you have to do is sort your data set to have the Z observation on the very first observation. Then read the dataset with a DATA step, and

[pre]

RETAIN Zvalue ;

IF _N_=1 THEN Zvalue = value ;

[/pre]

The RETAIN instruction will ensure that the value is remembered for any further observation read.

If there are several values to remember, declare every variable in a single RETAIN, and create them in the IF _N_=1 statement. You can use ARRAYs to simplify syntax, working on week_1, week_2, etc.

Regards.

Olivier

What you have to do is sort your data set to have the Z observation on the very first observation. Then read the dataset with a DATA step, and

[pre]

RETAIN Zvalue ;

IF _N_=1 THEN Zvalue = value ;

[/pre]

The RETAIN instruction will ensure that the value is remembered for any further observation read.

If there are several values to remember, declare every variable in a single RETAIN, and create them in the IF _N_=1 statement. You can use ARRAYs to simplify syntax, working on week_1, week_2, etc.

Regards.

Olivier

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

Posted in reply to Olivier

07-02-2008 05:54 AM

Hi Olivier,

Many thanks for your reply.

I am not sure to well understand. I have to create new variables for each week_i of my Z(last or first) row?

Here is the macro:

%Macro DUMMY_PERF_HEBDO (table=) ;

data &table.2 (drop=monthly_perf_week_1-monthly_perf_week_500);

set &table ;

array monthly_perf_week_[&_N_week] monthly_perf_week_1-monthly_perf_week_500;

array dummy_week_[500] dummy_week_1-dummy_week_500;

retain monthly_perf_week_1-monthly_perf_week_500 dummy_week_1-dummy_week_500 ;

/*ATTENTION aux 1 premières données week_n*/

do _i=5 to 500;

If (monthly_perf_week_(_i)=0 or monthly_perf_week_(_i)=.) then dummy_week_(_i)=.;

ELSE if BETA =0 then dummy_week_(_i)=.;

Else dummy_week_(_i)=(monthly_perf_week_(_i)-BETA*(monthly_perf_week_(_i)/* THE LAST OR FIRST ROW */ );

End;

run;

%Mend ;

Thanks,

Many thanks for your reply.

I am not sure to well understand. I have to create new variables for each week_i of my Z(last or first) row?

Here is the macro:

%Macro DUMMY_PERF_HEBDO (table=) ;

data &table.2 (drop=monthly_perf_week_1-monthly_perf_week_500);

set &table ;

array monthly_perf_week_[&_N_week] monthly_perf_week_1-monthly_perf_week_500;

array dummy_week_[500] dummy_week_1-dummy_week_500;

retain monthly_perf_week_1-monthly_perf_week_500 dummy_week_1-dummy_week_500 ;

/*ATTENTION aux 1 premières données week_n*/

do _i=5 to 500;

If (monthly_perf_week_(_i)=0 or monthly_perf_week_(_i)=.) then dummy_week_(_i)=.;

ELSE if BETA =0 then dummy_week_(_i)=.;

Else dummy_week_(_i)=(monthly_perf_week_(_i)-BETA*(monthly_perf_week_(_i)/* THE LAST OR FIRST ROW */ );

End;

run;

%Mend ;

Thanks,

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

Posted in reply to deleted_user

07-02-2008 07:17 AM

Hi olivier,

I've added new variables and it works very well!

The "RETAIN Zvalue ;IF _N_=1 THEN Zvalue = value ;" codes is repeating the value in each cell of the column.

Thanks a lot,

anais

I've added new variables and it works very well!

The "RETAIN Zvalue ;IF _N_=1 THEN Zvalue = value ;" codes is repeating the value in each cell of the column.

Thanks a lot,

anais