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
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;
Pleae post the complete log of your step.
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;
thanks @Ksharp , it worked.
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;
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!
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.