BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mathias
Quartz | Level 8

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 ?

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

PG

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

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

PG
mathias
Quartz | Level 8

Works great outside a macro, but how would you run this inside a macro (which does not accept datalines statements) ?

Tom
Super User Tom
Super User

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?

  • If it is already in a dataset then process the dataset as PG suggests.
  • If it is in a macro variable then
    • you could just replace his SET TEST line with LINE="&macrovarname" statement instead.
    • Or you could translate the data step into the equivalent statements in macro code use %SYSFUNC()
mathias
Quartz | Level 8

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1121 views
  • 3 likes
  • 3 in conversation