Hi everyone. I am currently looking at codes written by other programmers but I do not understand the purpose of it.
Here are the codes :
attrib state_code length=$5 label='State Code';
attrib state length=$30 label='State Name';
attrib state_zone_id length=$30 label='State Zone ID';
attrib state_zone_code length=$30 label='State Zone Code';
attrib state_zone_name length=$30 label='State Zone Name';
*attrib gis_state length=8 label='GIS State No';
attrib data_dttm length=8 format=datetime. label='Data Date and Time';
set man_dim_state (firstobs=2);
region=A;
zone=put(input(put(B, 2.),2.),z2.);
state_code=C;
state=D;
state_zone_id=E;
state_zone_code=F;
state_zone_name=G;
As you can see, the bottom portion of the code is basically assigning english letter to it. However, there is no such value in the output with C D E F. Moreover, there is also no such column C D E F but the original name(StateXXX).
Can anyone explain the possible reasons for these codes?
A, B, C, D, E, F are variables. If these variables are not present in the man_dim_state data set, then the assignment statements will fail, and they should not be present.
Look at the whole code of that step. There's either a set that reads from a dataset, or infile and input that read from an external file.
Correction: there is a set, just not where I would write it 😉
If columns A to G are not present in your resulting dataset, they are dropped somewhere along the way (either with a drop statement or a drop= dataset option).
This code expects that the incoming data set contains variables named A, B, C, D, E, F, G. It probably drops these variables later in the DATA step (we know you are not showing the entire DATA step here).
The intention of the code:
The data gets converted to a structure that uses different variable names, with different lengths and labels for the variables.
@Astounding wrote:
This code expects that the incoming data set contains variables named A, B, C, D, E, F, G. It probably drops these variables later in the DATA step (we know you are not showing the entire DATA step here).
The intention of the code:
The data gets converted to a structure that uses different variable names, with different lengths and labels for the variables.
And at a guess to go along with @Astounding, this code smells like it is "fixing" poorly imported data to match a defined set of characteristics. Possibly so data sets can be combined.
If your code in the scheme of this process shows use of Proc Import code then the data reading process is suspect and fixes like this become common when relying on Proc Import for reading multiple similar files.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: