- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It's more for the readability than for the functionality.
proc contents data=sashelp.cars out=namy;
run;
%let abc=put text here;
ods escapechar = '`';
proc sql noprint;
select catx(' ', '{name=', quote(strip(name)), "label=", %sysfunc(quote("&abc")), '}') into :oks separated by ", (*ESC*) {unicode '000A'x} "
from WORK.namy where label = '';
quit;
%put %bquote(&oks.);
The log shows:
{name= "Cylinders" label= "put text here" }, (*ESC*) {unicode '000A'x} {name= "DriveTrain" label= "put text here" }, (*ESC*)
{unicode '000A'x} {name= "Horsepower" label= "put text here" }, (*ESC*) {unicode '000A'x} {name= "Invoice" label= "put text here"
}, (*ESC*) {unicode '000A'x} {name= "MSRP" label= "put text here" }, (*ESC*) {unicode '000A'x} {name= "Make" label= "put text
here" }, (*ESC*) {unicode '000A'x} {name= "Model" label= "put text here" }, (*ESC*) {unicode '000A'x} {name= "Origin" label= "put
text here" }, (*ESC*) {unicode '000A'x} {name= "Type" label= "put text here" }
But I would like to have:
%put %bquote(&oks.);
{name= "Cylinders" label= "put text here" },
{name= "DriveTrain" label= "put text here" },
{name= "Horsepower" label= "put text
here" },
{name= "Invoice" label= "put text here" },
{name= "MSRP" label= "put text here" },
{name= "Make" label= "put text here" },
{name= "Model" label= "put text here" },
{name= "Origin" label= "put text here" },
{name= "Type" label= "put text here" }
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Why does the "want" for Horsepower show a line break after "text"? That's going to be a serious difference of logic if intentional.
Where do you expect this to display? Is this only for the log or elsewhere? I'm not sure that the unicode characters display well in the LOG.
Any particular reason you didn't use the NEWLINE function instead of the unicode character? Not that the LOG likes that any better in a macro variable.
Here's an example, that depending on your settings may display something similar to what you want in the results window using FILE PRINT with PUT. Remove the File Print and see what the LOG shows for why I commented about unicode and inline formatting.
Then a Proc Print of a variable built.
data junk (keep=lngstr); set namy (where= (name in ("Cylinders" "DriveTrain"))) end=lastone ; length lngstr $5000 ; retain lngstr; lngstr = catx(",(*ESC*){newline}",strip(lngstr), catx(' ', '{name=',quote(strip(name)), "label=", quote(strip("&abc")), '}')); file print; if lastone then do; put lngstr; call symputx('oks2',strip(lngstr)); output; end; run; %put %bquote(&oks2.); proc print data=junk noobs; var lngstr; run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Why does the "want" for Horsepower show a line break after "text"? That's going to be a serious difference of logic if intentional.
Where do you expect this to display? Is this only for the log or elsewhere? I'm not sure that the unicode characters display well in the LOG.
Any particular reason you didn't use the NEWLINE function instead of the unicode character? Not that the LOG likes that any better in a macro variable.
Here's an example, that depending on your settings may display something similar to what you want in the results window using FILE PRINT with PUT. Remove the File Print and see what the LOG shows for why I commented about unicode and inline formatting.
Then a Proc Print of a variable built.
data junk (keep=lngstr); set namy (where= (name in ("Cylinders" "DriveTrain"))) end=lastone ; length lngstr $5000 ; retain lngstr; lngstr = catx(",(*ESC*){newline}",strip(lngstr), catx(' ', '{name=',quote(strip(name)), "label=", quote(strip("&abc")), '}')); file print; if lastone then do; put lngstr; call symputx('oks2',strip(lngstr)); output; end; run; %put %bquote(&oks2.); proc print data=junk noobs; var lngstr; run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @ballardw , that's it.
I use it to create a code snippet that I paste to a the cas action altertable.
And for the sake of readability of the code I was looking the linebreak.
cas mySession sessopts=(caslib="public");
proc cas;
table.alterTable /
columns={
{name= "BATCH_ID" label= "BATCH ID derived from recipe and its start time" },
{name= "BATCH_ID_dt" label= "BATCH ID derived from recipe and its start time in datetime format" }
},
name="have_table";
table.fetch / table="have_table"
fetchvars={"&vars"},
index=false;
quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Here's another option if you want to save them into separate macro variables:
proc contents noprint data=sashelp.cars out=namy (keep=name label); run;
data _null_;
set namy end=last;
nm=quote(strip(name));
lbl=quote("put text here");
c=',';
if last then c='';
msg=compbl('{ name= ' || nm ||' label=' || lbl || '}' || c);
put msg;
call symputx(compress("msg" || _N_), msg);
run;
* for example, the 3rd name/label combination ;
%put MSG3: &msg3;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Create CODE SNIPPETS??
Can you clarify what that means.
If you want to insert linebreak that it put the data into a FILE, not a macro variable.
filename snippet temp;
proc contents data=sashelp.class noprint out=contents; run;
proc sort data=contents;
by varnum;
run;
data _null_;
file snippet;
set contents end=eof;
if _n_=1 then put @2 'columns=' / @4 '{' @;
else put @4 ',' @;
put '{' name= :$quote. label= :$quote. '}';
if eof then put @4 '},' ;
run;
Result:
columns= {{NAME="Name" LABEL="" } ,{NAME="Sex" LABEL="" } ,{NAME="Age" LABEL="" } ,{NAME="Height" LABEL="" } ,{NAME="Weight" LABEL="" } },