BookmarkSubscribeRSS Feed
Julo
Calcite | Level 5
Hello,

this assingment works in sas.
%let arr = 'aaa', 'bbb', 'ccc';

The "arr" variable contains the array of 3 strings? Or it contains only one long string?

Because when i pass the "arr" variable to %substr function, it fail because the variable contains comma, which is also separator in function arguments.

My question is
- in case if arr variable is array of strings, how can I reference particular items?
- in case it is only one string, how can i handle special character (comma) in the string?

Thanks for an answer
4 REPLIES 4
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Explain exactly how you expect to use the data - what type of SAS code, DATA step, PROC SQL, MACRO usage? Also, provide a SAS-generated log where you are using the string with your %LET revealed and all other code, embedded in a SAS program - use COPY / PASTE for your log to add to a forum post-reply.

Scott Barry
SBBWorks, Inc.
ballardw
Super User
Your ARR contains a single string.

Before dealing with options on handling, it does help to how the how thing is used. For most purposes in a macro both the quotes around your values and the commas are likely to be unneeded.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Though data-strings can be addressed in various methods using SAS, I have to say that sometimes the specific intent is to provide the quoted-string and use it somehow where such a data-value is supplied, such as using a WHERE statement with an "IN" operator.

On occasion, a "flower boxed" %LET statement is used to reveal a "prompt like" interaction from an end-user who has been given a self-contained SAS program, where the only interaction is to "fill in the desired filter values, in quote-marks".

Scott Barry
SBBWorks, Inc.
chang_y_chung_hotmail_com
Obsidian | Level 7
...

> this assingment works in sas.

> %let arr = 'aaa', 'bbb', 'ccc';

>

> The "arr" variable contains the array of 3 strings?

> Or it contains only one long string?



It is a value that is assigned to a macro variable. Macro variables store text, or a string of characters.



> Because when i pass the "arr" variable to %substr

> function, it fail because the variable contains

> comma, which is also separator in function

> arguments.



Yes, this is expected.



> My question is

...

> - in case it is only one string, how can i handle

> special character (comma) in the string?



By quoting, that is, hiding the comma's from macro processor.



   %let arr = %str('aaa', 'bbb', 'ccc');


   %put first word = %scan(&arr, 1, %str(,));


   %put second word = %scan(&arr, 2, %str(,));


   %*-- on log


   first word = 'aaa'


   second word =  'bbb'


   --*;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 2312 views
  • 0 likes
  • 4 in conversation