BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Caetreviop543
Obsidian | Level 7

I have a variable with a long text string:

 

 

Text
something 1- something 2
some 4
text2-text3-text4-text5

 

SAS prints the text to look like this:

Text
something 1 - somet
some 4
text2-text3-text4-text

SAS will not print the variable with the updated length, despite recognizing in proc contents that I've changed the length, the format length, and the informat length to 32 characters (the text doesn't exceed 32 characters). This was the code I used:

 

data want;
length Text $32;
format Text $32.;
set have;

***
code
***

informat Text $32.;
run;

 

In the past, I've never had to use a special option in proc print to print the full variable with the updated length. But I tried:

 

proc print data=have width = full;
run;

and it didn't work. Any ideas? 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@Caetreviop543 wrote:

Ok, it's a csv file. I imported it using proc import:

 

filename REFILE "/directory/filename";

libname out "/directory/out/";

 

proc import datafile = REFILE 

dbms = csv

out = out.filename replace;

getname = yes;

run;

 

 

 


add:  Guessingrows = max;

Unless your file is real big. Then use a numeric value like: Guessingrows=32000;

 

the proc import. The procedure will examine more values before setting the actual length of the variables. Otherwise the proc only looks at the first 20 rows to guess how long the values should be.

View solution in original post

7 REPLIES 7
Reeza
Super User
How did you read in the data? Most likely it was truncated when it was read in so you need to fix that first.
Caetreviop543
Obsidian | Level 7

Ok, it's a csv file. I imported it using proc import:

 

filename REFILE "/directory/filename";

libname out "/directory/out/";

 

proc import datafile = REFILE 

dbms = csv

out = out.filename replace;

getname = yes;

run;

 

 

 

ballardw
Super User

@Caetreviop543 wrote:

Ok, it's a csv file. I imported it using proc import:

 

filename REFILE "/directory/filename";

libname out "/directory/out/";

 

proc import datafile = REFILE 

dbms = csv

out = out.filename replace;

getname = yes;

run;

 

 

 


add:  Guessingrows = max;

Unless your file is real big. Then use a numeric value like: Guessingrows=32000;

 

the proc import. The procedure will examine more values before setting the actual length of the variables. Otherwise the proc only looks at the first 20 rows to guess how long the values should be.

Caetreviop543
Obsidian | Level 7

Thanks, I tried that but it didn't work. It says it correctly applied the length, format and informat in proc contents. However, when I try to select the record with the full name, it says it doesn't exist. It only recognizes the shortened name. 

ballardw
Super User

@Caetreviop543 wrote:

Thanks, I tried that but it didn't work. It says it correctly applied the length, format and informat in proc contents. However, when I try to select the record with the full name, it says it doesn't exist. It only recognizes the shortened name. 


I'm afraid that really isn't very help helpful. Formats and informats can be assigned that do not actually match variable lengths and odd things may seem to happen.

 

Can you share the actual data involved? Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against. Or if you data started as CSV or similar text format then provide lines of the data, again pasting into the code box, and the code you used to create a SAS data set from the values.

 

If the specific values are sensitive then generate a set with the sensitive values replaces with nonsense characters but that behaves exactly the same as your current data. And then share the actual code.

 

When you use code similar to this:

data want;
length Text $32;
format Text $32.;
set have;

informat Text $32.;
run;

If the length of the variable in HAVE was less than 32 this will NOT add any characters to the value. It was already cut off when the HAVE (or earlier) data set was created. See below. Also shown is that by default Proc Print will left justify removing leading blanks for display. Which is something else that may be happening with your data. Which is why I ask for the actual data.

 

data example;
   text='abcd';
   othertext='      pdq';
run;

data want;
length Text $32;
format Text $32.;
set example;
informat Text $32.;
run;

proc print data=want;
run;

Note that if you run Proc Contents on the WANT data set created above the Text variable will report having length 32, format $32 and informat $32. But it can only display 4 characters because that is what was originally created for the example data value.

Caetreviop543
Obsidian | Level 7

Thanks for your help. Yes, you and Reeza are right; the issue was that the variable was truncated during the import. For some reason guessingrows = 20,000, but not guessingrows = max, worked. I have no idea why. 

 

 

Kurt_Bremser
Super User

@Caetreviop543 wrote:

Ok, it's a csv file. I imported it using proc import:

 

filename REFILE "/directory/filename";

libname out "/directory/out/";

 

proc import datafile = REFILE 

dbms = csv

out = out.filename replace;

getname = yes;

run;

 

 

 


Why don't you write a data step according to the documentation you got with the file?

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 7 replies
  • 1238 views
  • 2 likes
  • 4 in conversation