SAS ARRAY 1

SAS DAY 9: ARRAY

Problem:
We want to assign values for QSSTRESN such that it matches with the variable QSTESTCD.

(E.g. QSTESTCD=”EQ5D01″, QSTRESN=QS1)

Desired Output:

USUBJID QSTESTCD QS1 QS2 QS3 QS4 QS5 QSSTRESN
TF001 EQ5D01 1 1 1 1 1 1
TF001 EQ5D02 1 1 2 1 1 1
TF001 EQ5D03 1 1 3 1 2 3
TF001 EQ5D04 1 2 1 1 1 1
TF001 EQ5D05 1 1 3 1 2 2

 

maciej326 / Pixabay

Solution:

  1. Use ARRAY create navlue to hold qs1 to qs5
  2. Generate a do loop with variable {i}
  3. Assign each qs{i} value to QSSTRESN

 

SAS Code:

array nvalue{*} QS1 QS2 QS3 QS4 QS5;
do i=1 to dim(nvalue);
if nvalue{i} ne “” then QSSTRESN=nvalue{i};
end;

Happy SAS Coding! 🤗

 

  One thought on “SAS ARRAY 1

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Social media & sharing icons powered by UltimatelySocial
%d bloggers like this: