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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 737 views
  • 4 likes
  • 3 in conversation