DATA Step, Macro, Functions and more

Format variable

Reply
Contributor
Posts: 34

Format variable

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

 

 

 

Super User
Posts: 19,855

Re: Format variable

Add a length statement.

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

Re: Format variable

Hi Reeza, thanks for this.

I tried it and the problem remains.
But why did you write 8? I want 6! ^^
Super User
Posts: 19,855

Re: Format variable


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;
Super User
Posts: 11,343

Re: Format variable

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.

Ask a Question
Discussion stats
  • 4 replies
  • 80 views
  • 0 likes
  • 3 in conversation