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'


   --*;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1424 views
  • 0 likes
  • 4 in conversation