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!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1306 views
  • 2 likes
  • 2 in conversation