Hi,
I have a string (that comes from a multiple select in a stp)
that looks like this:
('BORPER','BRR_SP','CHL_PN')
and I have a format for these 3 values (e.g. BORPER="Bordetella pertussis")
Is there a way to apply my format to each value of my string rather than the whole string ?
Something like this?
data test;
attrib line length=$100;
input line &;
datalines;
('BORPER','BRR_SP','CHL_PN')
;
proc Format;
value $ myFormat
"BORPER"="Bordetella pertussis"
"BRR_SP"="Some sort of BRR"
"CHL_PN"="What is CHL PN?"
OTHER="Other species"
;
run;
data want(keep=line newline);
attrib newLine length=$100;
set test;
do i = 1 by 1;
word = scan(line,i,"'(), ");
if missing(word) then leave;
newLine = catx(",",newLine,cats("'",put(word,$myFormat.),"'"));
end;
newLine = cats('(',newLine,')');
run;
PG
Something like this?
data test;
attrib line length=$100;
input line &;
datalines;
('BORPER','BRR_SP','CHL_PN')
;
proc Format;
value $ myFormat
"BORPER"="Bordetella pertussis"
"BRR_SP"="Some sort of BRR"
"CHL_PN"="What is CHL PN?"
OTHER="Other species"
;
run;
data want(keep=line newline);
attrib newLine length=$100;
set test;
do i = 1 by 1;
word = scan(line,i,"'(), ");
if missing(word) then leave;
newLine = catx(",",newLine,cats("'",put(word,$myFormat.),"'"));
end;
newLine = cats('(',newLine,')');
run;
PG
Works great outside a macro, but how would you run this inside a macro (which does not accept datalines statements) ?
Huh?
The data step was just there to setup an example dataset so that PG could post a working example.
What is the source of the string?
Big thanks to PGstats !
found it with proc sql :
proc sql;
create table test
(germs char(100));
quit;
proc sql;
insert into test
(germs)
values("('BORPER','BRR_SP','CHL_PN')");
quit;
data _null_(keep=germs latinGerm);
attrib latinGerm length=$100;
set test;
do i = 1 by 1;
word = scan(germs,i,"'() ,'");
if missing(word) then leave;
latinGerm = catx(" & ",latinGerm,cats("",put(word,&formatGerm.),""));
end;
/*latinGerm = cats('(',latinGerm,')');*/
call symputx ('displayGerms',latinGerm);
run;
%put &displayGerms;
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.
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.