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
- /
- Data Management
- /
- Forum
- /
- Representation of column numbers

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

07-02-2015 08:16 AM

Dear all,

Today i came with another stupid question, That i am having problem with column representation and the dataset given bellow

Now I need to create another dataset with all these variables and an extra variable which is calculated from T1, T2, T3, T4, Lower. Consider T1 as 1, T2 as 2, T3 as 3, T4 as 4. nSuppose ” lower” contains value 0.53 which is positioned at “T2” so the new variable will contains 2 and “lower “ is 1 then new variable contains 3 ……

For the above dataset the calculated result will be given in dataset bellow. Resulted variable spoted in green color.

Thanks in advance.

Accepted Solutions

Solution

07-30-2016
07:19 AM

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

07-02-2015 09:07 AM

The more succinct code is :

data have;

input t1-t4 low;

cards;

0 0.51 1 2 1

0 0.53 1 2.02 0.53

;

run;

data want;

set have;

array x{*} t:;

first=whichn(low,of x{*});

run;

All Replies

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

07-02-2015 08:47 AM

This is simple enough, I was trying to find a simpler solution using scan but didn't get there. I'm hoping someone comes up with something more eligant in case this is a situation with a large dataset.

data have;

infile cards dsd dlm= ' ';

input c1 c2 t1 t2 t3 t4 lower;

cards;

.7514 10.215 0 .51 1 2 1

1.08674 9.123 0 .53 1 2.02 .53

1.2134 10.324 0 .5 1 2 2

.23421 12.1234 0 .5 1.03 2 1.03

;

run;

data want;

set have;

if lower = t1 then first = 1;

else if lower = t2 then first = 2;

else if lower = t3 then first = 3;

else if lower = t4 then first = 4;

run;

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

07-02-2015 08:54 AM

data have;

input t1-t4 low;

cards;

0 0.51 1 2 1

0 0.53 1 2.02 0.53

;

run;

data want;

set have;

array x{*} t1-t4;

do i=1 to dim(x);

if x{i}=low then do;first=i;leave;end;

end;

drop i;

run;

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

07-02-2015 08:57 AM

Xia,

I think I've seen this but do not remember the solution, if you do not know how many t values there are is there a way to say array x{*} t1-t 'nth; ?

Thanks,

Solution

07-30-2016
07:19 AM

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

07-02-2015 09:07 AM

The more succinct code is :

data have;

input t1-t4 low;

cards;

0 0.51 1 2 1

0 0.53 1 2.02 0.53

;

run;

data want;

set have;

array x{*} t:;

first=whichn(low,of x{*});

run;

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

07-02-2015 08:56 AM

Hi,

data want;

set have;

array t{4};

do i=1 to 4;

if t{i} <= lower and first=. then first=i;

end;

run;