DATA Step, Macro, Functions and more

Tranwrd with variables

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

Tranwrd with variables

[ Edited ]
 
data have1;
  input folder1 :$60. ;
cards;
F:/Drive1/Dataset/Table1
F:/Drive2/Dataset/Table2
F:/Drive3/Table
F:/Drive4
;
data have2;
  input folder2 :$60. linux $60.;
cards;
F:/Drive1 /sas/data/drive1
F:/Drive2  /sas/data/drive2
F:/Drive1/Dataset  /sas/data/dataset
F:/Drive2/Dataset  /sas/data/dataset
F:/Drive3/  /sas/data/drive3
;
proc sql;
create table test as 
select *
    from have1, have2
where scan(folder1,1,'/') =scan(folder2,1,'/') ; 
quit;
 
 
data a;
set test;
folder1 = tranwrd(folder1,folder2,linux);
run;
 
The Tranwrd function is not working well (no replacement done).
Any ideas?
Thank you

Accepted Solutions
Solution
‎08-30-2017 03:56 AM
Super User
Super User
Posts: 7,074

Re: Tranwrd with variables

You need to trim the values passed to the TRANWRD() function since SAS stores variables as fixed length.  You asked tranwrd to find values with many trailing spaces that are probably not actually in the values.

linux_folder1 = tranwrd(folder1,trim(folder2),trim(linux));

 

View solution in original post


All Replies
SAS Super FREQ
Posts: 305

Re: Tranwrd with variables

try trimming folder2: trim(folder2)

Trusted Advisor
Posts: 1,583

Re: Tranwrd with variables

Posted in reply to WarrenKuhfeld

In all your rows:  scan(folder1,1,'/')  ='F:'scan(folder2,1,'/');

 

Did you mean:

    where scan(folder1, -1,'/') = trim(folder2)

 

Solution
‎08-30-2017 03:56 AM
Super User
Super User
Posts: 7,074

Re: Tranwrd with variables

You need to trim the values passed to the TRANWRD() function since SAS stores variables as fixed length.  You asked tranwrd to find values with many trailing spaces that are probably not actually in the values.

linux_folder1 = tranwrd(folder1,trim(folder2),trim(linux));

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 107 views
  • 1 like
  • 4 in conversation