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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: