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

Hi,

 

I am creating a new column called "group" in my dataset based on the value of another column. The real code I run has many more if conditions but the "group" column has only 3 values; indeterminate, not performance, performance. 

In the output, I have "not performan" rather than "not performance". Why do I have the last 2 letters dropped and how do I fix it?

 

data mydata;
set mydata;
	if reason = "asd asd asd" then group = "indeterminate";
	if reason = "abc abc abc" then group = "indeterminate";
	if reason=" xxx" then group="not performance"; 
if reason=" yy " then group="performance"; else cancellation_grouping = "other"; run;

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
sbxkoenk
SAS Super FREQ

Hello,

 

Length of GROUP variable is decided upon when GROUP gets its first value.

If first value assigned is 'ABC' then length becomes 3 and all other values (assigned later) are truncated as from the 4th position.

 

You can change the way length is determined by explicitly specifying the length yourselves for GROUP variable, like here :

 

data mydata;
 LENGTH group $ 15;
 set mydata;
	if reason = "asd asd asd" then group = "indeterminate";
	if reason = "abc abc abc" then group = "indeterminate";
	if reason=" xxx" then group="not performance";     if reason=" yy " then group="performance"; 
	 else cancellation_grouping = "other";
run;
/* end of program */


Koen

View solution in original post

4 REPLIES 4
sbxkoenk
SAS Super FREQ

Hello,

 

Length of GROUP variable is decided upon when GROUP gets its first value.

If first value assigned is 'ABC' then length becomes 3 and all other values (assigned later) are truncated as from the 4th position.

 

You can change the way length is determined by explicitly specifying the length yourselves for GROUP variable, like here :

 

data mydata;
 LENGTH group $ 15;
 set mydata;
	if reason = "asd asd asd" then group = "indeterminate";
	if reason = "abc abc abc" then group = "indeterminate";
	if reason=" xxx" then group="not performance";     if reason=" yy " then group="performance"; 
	 else cancellation_grouping = "other";
run;
/* end of program */


Koen

znhnm
Quartz | Level 8
Hello, thank you so much!

When I try it, I have an error saying:

Expecting an arithmetic operator.

What could be the reason of it?
sbxkoenk
SAS Super FREQ

Hello,

 

Can you post the LOG?

Copy the LOG , click on the </> icon in the toolbar on top when replying , then paste LOG in pop-up window!

Also, you might want :

if ; else if ; else if ; else if ; else ;

instead of 4 times if + an else ?

 

Thanks,

Koen

 
znhnm
Quartz | Level 8
Hi Koen,

I realized that I made a typo. Sorry about it. Your suggestion works perfectly. Appreciated your help!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 686 views
  • 2 likes
  • 2 in conversation