Help using Base SAS procedures

how to select column based on day(row is fixed)?

Reply
Contributor
Posts: 21

how to select column based on day(row is fixed)?

HI,

Name  F1 F2 F3 F4 F5 F6 .. . ..
1Cycle  34 35 23 23 12 89
2Cycle 78 90 78 57 45 67
3Cycle 67 87 45 43 89 64
.
.
.
10cycle 56 45 79 90 45 78


I am having a data set like above which has a whole month data(here I have just spcified 7 columns)
I want to retrive 3rd row data which is fixed and column will be chnaging on the day basis and after retriving the value, assign the value into
a macro variable.
for ex  on 4th feb it should select (row 3 and F4 column)=value should give 43
           on the 24th feb (row 3 and F24 column)

Let me know if i am not enough clear.

Thanks

Sudtej

Respected Advisor
Posts: 3,156

Re: how to select column based on day(row is fixed)?

Not sure if this is what you want. Following code will put the value of the third row, column(days) you choose into macro variable 'want'.

data have;

input Name $  F1 F2 F3 F4 F5 F6 ;

cards;

1Cycle  34 35 23 23 12 89

2Cycle 78 90 78 57 45 67

3Cycle 67 87 45 43 89 64

;

%macro test (d=);

data _null_;

n=3;

set have point=n;

call symput ('want',f&d);

stop;

run;

%put &want;

%mend;

%test (d=6)

Edit:

For more general purpose, the code can also be slightly tweaked like the following, so you can also choose the row of your will.

%macro test (r= ,c=);

data _null_;

n=&r;

set have point=n;

call symput ('want',f&c);

stop;

run;

%put &want;

%mend;

%test (r=2, c=3)

Regards,

Haikuo

PROC Star
Posts: 7,492

Re: how to select column based on day(row is fixed)?

How is the code supposed to know that February is represented on the 3rd record?  What do records one and two represent?  Do you just want to indicate the date upfront and have the code take care of everything else?

Contributor
Posts: 21

Re: how to select column based on day(row is fixed)?

Thanks. It works!

The whole table is for February, its one of the sheets of a workbook. The records 1, 2, 3 are different types of data which i receive on that particular day. So, I just modified your code to take the date as input & code is taking care of everything.

Ask a Question
Discussion stats
  • 3 replies
  • 125 views
  • 0 likes
  • 3 in conversation