BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
yahoo0806
Calcite | Level 5

Hi all,

Using the SAS code below, I can ask SAS to output the correct value from the column COL{i} when it meets the condition i specified in my code. However, i'm wondering how can I also ask SAS to tell me which COL{i} the value is coming from. 

In order word, prior_date is getting the values from the COL{i} column, I want to find a way to ask SAS also tell me which column the COL{i} is. Do you know how I can do it?

 

data ae_temp1;
set ae_temp1;
array col{*} col1 - col12;

do i = 1 to 11;
if length(aestdtc) = 10 then
do;
if col{i+1} ^= '' then
do;
if input(scan(col{i}, 1, 'T'), yymmdd10.) <= input(aestdtc, yymmdd10.) and input(scan(col{i+1}, 1, 'T'), yymmdd10.) > input(aestdtc, yymmdd10.) then
Prior_date = col{i};
end;

if col{i}^= '' and col{i+1} = '' then
do;
if input(scan(col{i}, 1, 'T'), yymmdd10.) <= input(aestdtc, yymmdd10.) then
prior_date = col{i};
end;
end;

end;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
if input(scan(col{i}, 1, 'T'), yymmdd10.) <= input(aestdtc, yymmdd10.) then do;
prior_date = col{i};
whichcolumn = i;
end;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
if input(scan(col{i}, 1, 'T'), yymmdd10.) <= input(aestdtc, yymmdd10.) then do;
prior_date = col{i};
whichcolumn = i;
end;
--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 731 views
  • 0 likes
  • 2 in conversation