BookmarkSubscribeRSS Feed
FP12
Obsidian | Level 7

Hi all,

 

I create a table using a proc sql:

PROC SQL;
CREATE TABLE A
(B char(6) label = "BA");
QUIT;

For every rows, the column B is filled in with "PA".

 

Finally the column B of my table A has a length of 2.

 

I would like it to remain to 6 as I ask it to do...because in a next step I merge with another table which has more than 2 characters and otherwise it creates truncation problems.

Do you  know how I could do it?

 

Thanks

 

 

 

4 REPLIES 4
Reeza
Super User

Add a length statement.

PROC SQL;
CREATE TABLE A
(B char(6) label = "BA" length=8);
QUIT;
FP12
Obsidian | Level 7
Hi Reeza, thanks for this.

I tried it and the problem remains.
But why did you write 8? I want 6! ^^
Reeza
Super User

@FP12 wrote:


But why did you write 8? I want 6! ^^

Then change it to 6.

 


@FP12 wrote:



I tried it and the problem remains.


Show what you tried and what the 'problem remains' means. Explain in detail, preferably using the example/code we can run. It works in the demonstration code I presented so either you're not stating something that's important or doing something else that's changing it somewhere else.

 

The output here clearly shows the length is now 8.

 

SAS Output

Alphabetic List of Variables and Attributes
# Variable Type Len Label
1 B Char 8 BA

 

PROC SQL;
CREATE TABLE A
(B char(6) label = "BA" length=8);
QUIT;

proc contents data=a;
run;
ballardw
Super User

You are obviously skipping something very important as there are no values for B shown. The empty data set created by the shown SQL does have a length of 6.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 644 views
  • 0 likes
  • 3 in conversation