BookmarkSubscribeRSS Feed
garag
Calcite | Level 5


Hi,

I'm trying to set a variable reading from a dataset some clumns value that should contains strange char as a single quote (') or &.

example:

data inputds;
   aaa = "aaa'aaa";
   bbb = 'bbb';
   ccc = "ccc'ccc'ccc";
   ddd = 'dd&dd';
run;


proc sql noprint;
  select aaa, bbb, ccc, ddd into :vara, :varb, :varc, :vard from inputds;
quit;

If I run
%put &vara;
%put &varb;
%put &varc;
%put &vard;

Sas does not work. Do there is a way to populate some variables in a safety way independently by what is is contains?

Many thanks

Regards,

Antonio

1 REPLY 1
Astounding
PROC Star

You can always get tricky characters into macro variables,.  As you have found out, utilizing them later may be difficult.

Just to display them, you can use:

%put %superq(vara);

%put %superq(varb);

%put %superq(varc);

%put %superq(vard);

In general, macro quoting functions such as %SUPERQ can temporarily mask the tricky characters.  Depending on how you want to use these values, you might need different quoting functions at various points within your code.

Good luck.

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!

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.

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
  • 1 reply
  • 794 views
  • 0 likes
  • 2 in conversation