DATA Step, Macro, Functions and more

What is the purpose of these extra assignment in code?

Reply
Frequent Contributor
Posts: 97

What is the purpose of these extra assignment in code?

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?

PROC Star
Posts: 1,400

Re: What is the purpose of these extra assignment in code?

Posted in reply to imdickson

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. 

Super User
Posts: 10,530

Re: What is the purpose of these extra assignment in code?

[ Edited ]
Posted in reply to imdickson

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 Smiley Wink

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

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 6,903

Re: What is the purpose of these extra assignment in code?

Posted in reply to imdickson

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.

Super User
Posts: 13,889

Re: What is the purpose of these extra assignment in code?

Posted in reply to Astounding

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

Ask a Question
Discussion stats
  • 4 replies
  • 56 views
  • 0 likes
  • 5 in conversation