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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 854 views
  • 2 likes
  • 3 in conversation