BookmarkSubscribeRSS Feed
Alexxxxxxx
Pyrite | Level 9

Dear all,

 

How can I put ' and " among ' ' in the following code?

 

%MACRO CompnayNameM(no=,Company_name=);

	Data DATASTREAM3_1&no.;
		Set Step9.Datastream_TOTAL_Step3_1;
		if findc(&COMPANY_NAME._Step23, '-’”'"#*@!?/&():;,. 1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ','K')>0;
		keep &COMPANY_NAME. &COMPANY_NAME._Step23;
	run;

%MEND CompnayNameM;
%CompnayNameM(no=1,Company_name=NAME)
%CompnayNameM(no=2,Company_name=COMPANY_NAME)
run;

Could you please give me some suggestions? thanks in advance.

3 REPLIES 3
Astounding
PROC Star

There's a general principle involved.  When using single quotes to denote a string, refer to a single quote inside the string as two consecutive single quotes.  For example:

 

'A''B'

 

refers to the same string as:

 

"A'B"

ballardw
Super User

@Alexxxxxxx wrote:

Dear all,

 

How can I put ' and " among ' ' in the following code?

 

%MACRO CompnayNameM(no=,Company_name=);

	Data DATASTREAM3_1&no.;
		Set Step9.Datastream_TOTAL_Step3_1;
		if findc(&COMPANY_NAME._Step23, '-’”'"#*@!?/&():;,. 1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ','K')>0;
		keep &COMPANY_NAME. &COMPANY_NAME._Step23;
	run;

%MEND CompnayNameM;
%CompnayNameM(no=1,Company_name=NAME)
%CompnayNameM(no=2,Company_name=COMPANY_NAME)
run;

Could you please give me some suggestions? thanks in advance.


You might be better off explaining which characters you are actually searching for. You have included in your list things that would appear with the modifiers UDP so the character list is way longer than needed.

AMSAS
SAS Super FREQ

Here's a quick example of how to get both single (') and double (") quotes into a string 

data _null_ ;
	string="abc'def""ghi" ;
	put string= ;
	
run ;


Note because I used double quotes for my string, I needed to use 2 sets of double  quotes inside the string

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 895 views
  • 1 like
  • 4 in conversation