Hello everyone,
I need to use WEIGHTED_PD columns based on YEAR_DIFF column. For example, if YEAR_DIFF=3 then NEW_COLUMN must get the value in column of WEIGHTED_PD3. However, it must get WEIGHTED_PD1 if YEAR_DIFF=0. Thanks in advance.
@Kıymet wrote:
Hello everyone,
I need to use WEIGHTED_PD columns based on YEAR_DIFF column. For example, if YEAR_DIFF=3 then NEW_COLUMN must get the value in column of WEIGHTED_PD3. However, it must get WEIGHTED_PD1 if YEAR_DIFF=0. Thanks in advance.
Are you asking how to use YEAR_DIFF to index into an ARRAY? Assuming you mean to use index of 1 when year_diff is less than 1 then perhaps just use a MAX() function call? If the rule is more complex you might need to instead use an IF/THEN construct.
So if you have 5 WEIGHTED_PDx variables in your dataset then you program might look like this:
data want;
set have;
array pd WEIGHTED_PD1-WEIGHTED_PD5;
new_column=pd[max(1,year_diff)];
run;
There is no WEIGHTED_PD1 column.
Please help us and provide data as working SAS data step code (examples and instructions) and not as a screen capture.
@Kıymet wrote:
Hello everyone,
I need to use WEIGHTED_PD columns based on YEAR_DIFF column. For example, if YEAR_DIFF=3 then NEW_COLUMN must get the value in column of WEIGHTED_PD3. However, it must get WEIGHTED_PD1 if YEAR_DIFF=0. Thanks in advance.
Are you asking how to use YEAR_DIFF to index into an ARRAY? Assuming you mean to use index of 1 when year_diff is less than 1 then perhaps just use a MAX() function call? If the rule is more complex you might need to instead use an IF/THEN construct.
So if you have 5 WEIGHTED_PDx variables in your dataset then you program might look like this:
data want;
set have;
array pd WEIGHTED_PD1-WEIGHTED_PD5;
new_column=pd[max(1,year_diff)];
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.