BookmarkSubscribeRSS Feed
imdickson
Quartz | Level 8

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?

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

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. 

Kurt_Bremser
Super User

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). 

Astounding
PROC Star

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.

ballardw
Super User

@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.

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
  • 4 replies
  • 606 views
  • 0 likes
  • 5 in conversation