Hello,
I have an array but the data is set up such that the array variables are separated by a binary variable. Does this matter to form the below variable called paymentsum or will SAS not recognize the array without the 3 variables lined up? When I do this, I don't always get the right answer so am wondering...
Thanks
Laura
array pay [3] paymentsum1-paymentsum3;
do p=1 to 3;
paymentsum=pay[p];
output;
end; drop p;
run;
Your code is fine and the position of the variables in the data vector will not impact it.
When using a single hyphen to make a variable list the names must have the same base and numeric suffix. So
paymentsum1-paymentsum3
is a shortcut for this list:
paymentsum1 paymentsum2 paymentsum3
When you use a double hyphen then to list is composed of the variables based on their order. So if your dataset had these 6 variables in this exact order:
paymentsum1 flag1 paymentsum2 flag2 paymentsum3 flag3
And you used a positional variable list like:
paymentsum1 -- paymentsum3
then that would mean these five variables:
paymentsum1 flag1 paymentsum2 flag2 paymentsum3
Hi @lmyers2 In a prod environment, the best bet is to list down names ones. Yes, that means typing each name in the array one by one. A one time effort. But in any case, it would help if you could post a representative sample of what you have for pointed answers. Thank you!
Your code is fine and the position of the variables in the data vector will not impact it.
When using a single hyphen to make a variable list the names must have the same base and numeric suffix. So
paymentsum1-paymentsum3
is a shortcut for this list:
paymentsum1 paymentsum2 paymentsum3
When you use a double hyphen then to list is composed of the variables based on their order. So if your dataset had these 6 variables in this exact order:
paymentsum1 flag1 paymentsum2 flag2 paymentsum3 flag3
And you used a positional variable list like:
paymentsum1 -- paymentsum3
then that would mean these five variables:
paymentsum1 flag1 paymentsum2 flag2 paymentsum3
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.