BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Tushar
Obsidian | Level 7

Hello Experts,

partition_Path=/vcs_valuation_type=FRTB/vcs_run_subtype=ES/vcs_run_qualifier=FC/cob_year=2022/cob_month=03/cobdate=20220304/package_type=FLASH/resu
lt_type=FRTB_TRADERBOOK_PNL/result_request_id=5;

 

formatted_partition= vcs_valuation_type="FRTB",vcs_run_subtype="ES",vcs_run_qualifier="FC",cob_year=2022,cob_month=03,cobdate=20220304,package_type

="FLASH",result_type="FRTB_TRADERBOOK_PNL",result_request_id=5;

 

i have written one simple program to get formatted_partition based on above requirement but with my program it also adding doble quote to digits value.

 

%let filePath=/vcs_valuation_type=FRTB/vcs_run_subtype=ES/vcs_run_qualifier=FC/cob_year=2022/cob_month=03/cobdate=20220304/package_type=FLASH/resu
lt_type=FRTB_TRADERBOOK_PNL/result_request_id=5;

data _null_;
temp=substr(tranwrd((tranwrd("&filePath",'/','",')),'=','="'),3);
form_path=compress(%sysfunc(cat(temp||'"')));
put form_path;
%let formPath=form_path;
run;

 

can anyone assist? @Ksharp @Tom 

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

Try

data _null_;
   length have want $ 500 pair $ 100 value $ 40;
   have = symget('partition_path');
   
   if first(have) = '/' then pp = substr(have, 2);
   
   do i = 1 to countw(have, '/');
      pair = scan(have, i, '/');
      value = scan(pair, 2, '=');
      
      want = catx(',', want, scan(pair, 1, '='));
      
      if anyalpha(value) then do;
         want = catx('=', want, quote(trim(value)));
      end;
      else do;
         want = catx('=', want, value);
      end;
   end;
   
   call symputx('formatted_path', want);
run;

View solution in original post

4 REPLIES 4
andreas_lds
Jade | Level 19

Try

data _null_;
   length have want $ 500 pair $ 100 value $ 40;
   have = symget('partition_path');
   
   if first(have) = '/' then pp = substr(have, 2);
   
   do i = 1 to countw(have, '/');
      pair = scan(have, i, '/');
      value = scan(pair, 2, '=');
      
      want = catx(',', want, scan(pair, 1, '='));
      
      if anyalpha(value) then do;
         want = catx('=', want, quote(trim(value)));
      end;
      else do;
         want = catx('=', want, value);
      end;
   end;
   
   call symputx('formatted_path', want);
run;
Tushar
Obsidian | Level 7
Thanks a lot, Work exactly i wanted.
Ksharp
Super User
%let filePath=/vcs_valuation_type=FRTB/vcs_run_subtype=ES/vcs_run_qualifier=FC/cob_year=2022/cob_month=03/cobdate=20220304/package_type=FLASH/result_type=FRTB_TRADERBOOK_PNL/result_request_id=5;

data x;
have=symget('filePath');
want=prxchange('s/\//,/i',-1,have);
want=prxchange('s/^,+//i',-1,want);

want=prxchange('s/(?<==)([a-z_]+)/"\1"/i',-1,want);

put have= / want=;
run;
Tushar
Obsidian | Level 7
Thanks a lot @Ksharp. This worked perfectly as well. Never thought of prxchange power. Going forward will use the same.

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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