DATA Step, Macro, Functions and more

quote string

Accepted Solution Solved
Reply
Super Contributor
Posts: 271
Accepted Solution

quote string

Hello,

 

I wonder why this does not add double quotes to name string.

 

data _null_;
  set sashelp.class;
  put name;
run;

data _null_;
  set sashelp.class;
  put "||name||";
run;

Accepted Solutions
Solution
‎11-27-2016 01:06 PM
Trusted Advisor
Posts: 1,022

Re: quote string

[ Edited ]
Posted in reply to SAS_inquisitive

You surround the expression

  || name ||

by quotes, which means sas willl treat it as a literal to be written by your put statemet.

 

Try

 put name $quote10. ;

 

which applies the $quote format  to name. Since name is 8  bytes, I  use 10 as the size attribute of the $quote format.

 

Mark

View solution in original post


All Replies
Solution
‎11-27-2016 01:06 PM
Trusted Advisor
Posts: 1,022

Re: quote string

[ Edited ]
Posted in reply to SAS_inquisitive

You surround the expression

  || name ||

by quotes, which means sas willl treat it as a literal to be written by your put statemet.

 

Try

 put name $quote10. ;

 

which applies the $quote format  to name. Since name is 8  bytes, I  use 10 as the size attribute of the $quote format.

 

Mark

Super Contributor
Posts: 271

Re: quote string

@mkeintz Thank you. I was asking this question in reference to use of variable in CALL EXECUTE routine. In example below, memname is not treated as literal.

data _null_;
	set _dsets_;
	call execute
		(
		'proc print data=sugi30.' ||
		trim(memname) ||
		'(obs=50); title ''First 50 observations of data set ' ||
		trim(memname) || '''; run;'
			);
run;
Trusted Advisor
Posts: 1,022

Re: quote string

Posted in reply to SAS_inquisitive

If you're trying to put quotes around the memname when it appears in the title, then use the put function, with $quote as 2nd argument, in the place where the variable memname appears in the title statement:

 

 

data _null_;

  set _dsets_;

  call execute

               (

       'proc print data=sugi30.' ||

                trim(memname) ||

       '(obs=50); title ''First 50 observations of data set ' ||

       put(memname,$quote10.) || '''; run;'

              ) ;

run;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 224 views
  • 1 like
  • 2 in conversation