BookmarkSubscribeRSS Feed
Bluekeys49
Obsidian | Level 7

Hi.  I am saving some data to a permanent SAS dataset.  I can easily do that, but notice when I do a "proc contents," my variable fields lengths are not what I want them to be in the saved dataset.  For example, I have a variables called GROUP1, GROUP2, and GROUP3 which have values of  1, 2, or 3.  Each variable is showing a character type with a length of 3 in proc contents.  I would like it to have length of 1 for each.  How and where do I indicate this in my program?  I tried the code below and it didn't work.  Perhaps my GROUP1 - GROUP3 is incorrect syntax?

 

* output to SAS perm dataset;
data dat1.tempdata;
  length GROUP1 - GROUP3 ($1.);
  set TWO ;
run;

2 REPLIES 2
ballardw
Super User

@Bluekeys49 wrote:

Hi.  I am saving some data to a permanent SAS dataset.  I can easily do that, but notice when I do a "proc contents," my variable fields lengths are not what I want them to be in the saved dataset.  For example, I have a variables called GROUP1, GROUP2, and GROUP3 which have values of  1, 2, or 3.  Each variable is showing a character type with a length of 3 in proc contents.  I would like it to have length of 1 for each.  How and where do I indicate this in my program?  I tried the code below and it didn't work.  Perhaps my GROUP1 - GROUP3 is incorrect syntax?

 

* output to SAS perm dataset;
data dat1.tempdata;
  length GROUP1 - GROUP3 ($1.);
  set TWO ;
run;


Such things should be fixed or set as early as practical. If you create these variables then the length should be set then, if you are reading them from an external data source that might be the place.

 

If these are coming from using Proc Import then perhaps another way to read the data should be investigated as there is NO way to know the properties of any variable as the procedure makes guesses separately for each file read.

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
  • 2 replies
  • 353 views
  • 2 likes
  • 3 in conversation