DATA Step, Macro, Functions and more

Change length of variable

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Change length of variable

Hi All,

 

i am reading the varaible and then using that in like statment, while doing this during comparision gwtting wrong output because of space(variable length), coul you please help.

 

data filesystemtable ;
infile "/home/cfile/filesystem.txt" ;
input filesystem :$30. ;
call symput('filesystem',filesystem);
run;

data Library_of_filesystem;
set mine;
where path like "&filesystem%";
keep path Library_name libref;
run;

 

log:
NOTE: There were 0 observations read from the data set WORK.MINE.
WHERE path like '/sas/bau/pricing/   %';

 

you can see as variable length is less than 30 hence space getting addedd while comparing and not getting expected result, could you please help to remove the leading space?


Accepted Solutions
Solution
‎03-09-2017 01:46 PM
Super User
Posts: 10,460

Re: Change length of variable

1) Try Call SymputX

 

2) what is the value of filesystem in the LAST record in the data set

 

3) you may need to examine that filesytem variable to see if it actually has NULL character(s) at the end and not a BLANK at the end. STRIP does not remove null characters.

View solution in original post


All Replies
Occasional Contributor
Posts: 8

Re: Change length of variable

Sharukhmk,

 

have you tried a simple solution? Try stripping the variable before assigning it.

 

variable = strip(variable);

 

Chirs

 

 

Super User
Posts: 10,460

Re: Change length of variable

Not really clear what the problem is as we really don't know any of your data.

I would guess that you may want

 

call symput('filesystem', STRIP(filesystem));

Occasional Contributor
Posts: 7

Re: Change length of variable

strip, trim and compress tried but still same thing.

Occasional Contributor
Posts: 8

Re: Change length of variable

What exactly are you trying to achieve with that code?

Occasional Contributor
Posts: 7

Re: Change length of variable

reading data and using that in where statement so i can filter out a table
.
Occasional Contributor
Posts: 8

Re: Change length of variable

 Seems like dataset "mine" is the issue, SAS is looking for a specific table. Maybe using _null_ will help? try this....

 

data Library_of_filesystem;

set _null_;

where path like "&filesystem%";

keep path Library_name libref;

run;

Occasional Contributor
Posts: 7

Re: Change length of variable

Mine table contains data and one of variable is path with which I am
comparing /sas/bau/pricing.

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Occasional Contributor
Posts: 7

Re: Change length of variable

data is : /sas/bau/pricing and issue is when i am reading it as $30. when comparing(using like) there is space coming ("/sas/bau/pricing ")which is not giving excpected result
Solution
‎03-09-2017 01:46 PM
Super User
Posts: 10,460

Re: Change length of variable

1) Try Call SymputX

 

2) what is the value of filesystem in the LAST record in the data set

 

3) you may need to examine that filesytem variable to see if it actually has NULL character(s) at the end and not a BLANK at the end. STRIP does not remove null characters.

Occasional Contributor
Posts: 7

Re: Change length of variable

the value of filesystem is /sas/bau/pricing
how can i test for blanks
Super User
Posts: 10,460

Re: Change length of variable

One way is use the Index function which returns the first position in the variable with a specified character.

data example;
   x='ThisHasNoBlanks';
   y='ThisHas A Blank'; /*blank being the SPACE character*/
   z='ThisHas Null'; /* Null character entered by typing 255 
                       on the NUMERIC key pad while holding the ALT key*/
   XhasBlank = index(x,' ');
   YhasBlank = index(y,' ');
   ZhasBlank = index(z,' '); /* space*/
   ZhasNull  = index(z,' '); /*ALT+255*/
run;
☑ This topic is SOLVED.

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

Discussion stats
  • 11 replies
  • 172 views
  • 1 like
  • 3 in conversation