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

data One;
input Date_Info $ 20.;
cards;
24Nov is Sunday
25Nov is Monday
26Nov is Tuesday
27Nov is Wednesday
28NOV IS THURSDAY
29nov is Friday
30NOV is SATURDAY
;
run;

data two;
set one;
a=scan(date_info,-1);
put a;
d=trim(a);
c=findw(date_info,d);
put c;
run;

 

Iam writing this code it giving c as zero always why?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

In SAS data sets, variables have a fixed length.  That length does not change from one observation to the next.  Therefore ...

 

When you assign a value to A, SAS defines A as character, with a length of 20.  It is possible that 20 characters would be needed to store A, so that's the length assigned.

 

Similarly, when you define D, SAS defines it as character with a length of 20.  Again, it is possible that 20 characters would be needed to store its value, so that's the length assigned.

 

When the TRIM function executes, it does remove trailing blanks.  However, the result gets stored in a variable that is defined as 20 characters long, so any blanks that were removed by TRIM get added back on again.  As a result, FINDW cannot find that 20-character string with all those trailing blanks.  

 

To remedy the situation, try:

 

c = findw(date_info, trim(a));

View solution in original post

2 REPLIES 2
Astounding
PROC Star

In SAS data sets, variables have a fixed length.  That length does not change from one observation to the next.  Therefore ...

 

When you assign a value to A, SAS defines A as character, with a length of 20.  It is possible that 20 characters would be needed to store A, so that's the length assigned.

 

Similarly, when you define D, SAS defines it as character with a length of 20.  Again, it is possible that 20 characters would be needed to store its value, so that's the length assigned.

 

When the TRIM function executes, it does remove trailing blanks.  However, the result gets stored in a variable that is defined as 20 characters long, so any blanks that were removed by TRIM get added back on again.  As a result, FINDW cannot find that 20-character string with all those trailing blanks.  

 

To remedy the situation, try:

 

c = findw(date_info, trim(a));

himanshu1
Calcite | Level 5

thanks alot for explaining the logic. now im able to uderstand the flow how its going. once again thank you.

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
  • 2 replies
  • 1494 views
  • 1 like
  • 2 in conversation