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

Hi,

 

I have two tables: orders, and returns

 

orders

v1 v2 v3 v4 v5
Orders Coffee Cup Amazon 2022-02-01 US

 

returns

v1 v2 v3 v4 v5 v6
Return Coffee Cup East Sales 2022-03-01 1

 

I expect to get result like:

v1 v2 v3 v4 v5 v6
Orders Coffee Cup Amazon 2022-02-01 US  
Return Coffee Cup East Sales 2022-03-01 1

 

However, after ran the code:

data want;
SET orders returns;
BY v2;
run;

I got:

v1 v2 v3 v4 v5 v6
Orders Coffee Cup Amazon 2022-02-01 US  
Return Coffee Cup East Sales 20 1

 

the v5 value in the Return category has been truncated automatically.

And I tried again by setting the length to a bigger value:

data want;
Length v1 $100 v2 $100 v3 $100 v4 $100 v5 $100 v6 $100;
SET orders returns;
BY v2;
run;

and it still gives me the same output.

 

Kindly advise.

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

After change the length of variables , you also need to change their FORMAT.

 

data want;
Length v1 $100 v2 $100 v3 $100 v4 $100 v5 $100 v6 $100;
SET orders returns;
BY v2;
format _character_ $200.;
run;

View solution in original post

4 REPLIES 4
Ksharp
Super User

After change the length of variables , you also need to change their FORMAT.

 

data want;
Length v1 $100 v2 $100 v3 $100 v4 $100 v5 $100 v6 $100;
SET orders returns;
BY v2;
format _character_ $200.;
run;
sarahzhou
Quartz | Level 8

thanks @Ksharp , it worked.

Kurt_Bremser
Super User

I should have caught what @Ksharp found.

But instead of setting a format (which can get you into the same trouble later), just remove them all:

data want;
length v1 $100 v2 $100 v3 $100 v4 $100 v5 $100 v6 $100;
set orders returns;
by v2;
format _character_;
run;

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
  • 1565 views
  • 4 likes
  • 3 in conversation