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

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?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

11 REPLIES 11
ChrisPillsbury
Obsidian | Level 7

Sharukhmk,

 

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

 

variable = strip(variable);

 

Chirs

 

 

ballardw
Super User

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));

Sharukhmk
Fluorite | Level 6

strip, trim and compress tried but still same thing.

ChrisPillsbury
Obsidian | Level 7

What exactly are you trying to achieve with that code?

Sharukhmk
Fluorite | Level 6
reading data and using that in where statement so i can filter out a table
.
ChrisPillsbury
Obsidian | Level 7

 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;

Sharukhmk
Fluorite | Level 6
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. -##
Sharukhmk
Fluorite | Level 6
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
ballardw
Super User

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.

Sharukhmk
Fluorite | Level 6
the value of filesystem is /sas/bau/pricing
how can i test for blanks
ballardw
Super User

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 11 replies
  • 2017 views
  • 1 like
  • 3 in conversation