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;
length group1-group3 $1;
@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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.