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

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;
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

 

 

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

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!

Tom
Super User Tom
Super User

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

 

 

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

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 861 views
  • 4 likes
  • 3 in conversation