[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sas-l
Subject:    StackOverflow: Using an observation value to reference a column in the same table in SAS
From:       Roger DeAngelis <rogerjdeangelis () GMAIL ! COM>
Date:       2017-03-28 14:20:49
Message-ID: 4537484813263194.WA.rogerjdeangelisgmail.com () listserv ! uga ! edu
[Download RAW message or body]

Using an observation value to reference a column in the same table in SAS


inspired by
https://goo.gl/lKxcnR
http://stackoverflow.com/questions/43064233/using-an-observation-value-to-reference-a-column-in-the-same-table-in-sas



HAVE
====

Up to 40 obs WORK.HAVE total obs=3

Obs    PERIOD    YEAR_1    YEAR_2    YEAR_3

 1        1        100       200       300
 2        2        100       200       300
 3        3        100       200       300


WANT
====

Up to 40 obs WORK.WANT total obs=3

                                               CHOSEN_
Obs    PERIOD    YEAR_1    YEAR_2    YEAR_3      YEAR

 1        1        100       200       300       100   Cjosen_year=year_<period>
 2        2        100       200       300       200
 3        3        100       200       300       300

SOLUTION
========

* make data;
data have;
input period year_1 year_2 year_3 ;
cards4;
1 100 200 300
2 100 200 300
3 100 200 300
;;;;
run;quit;

data want;
    set have;
    array years[*] year_:;
    chosen_year = years[period];
run;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic