An Idea Exchange for SAS software and services

Comments
by Super User
on ‎09-21-2017 03:08 PM

You may want to be a bit more detailed about exactly what is going on in this example.

You say you have a variable XYZ "where missing as been coded as -9". Is this done as a numeric assignment, an informat that read . as -9, a format that displays missing values as -9?

I believe that in two of the three cases nothing needs to be done for XYZm = xyz. to have the original missing value of xyy as missing for XYZm.

 

 

by Frequent Contributor
on ‎09-23-2017 12:55 PM

Sorry, my example wasn't very good.

 

I'm suggesting a function that enables the inheritance of all attributes, particularly the label.

 

Here is some code that illustrates the problem:

 

title 'Example';

data test;
attrib XYZ length=4 label="Variable of interest";
input ABC XYZ;
cards;
1 0027
2 0039
3 0103
4 -9
5 7890
;

data test2;
set test;
if XYZ = -9 then XYZm = .;
else XYZm = XYZ;
run;

proc contents data=test2;
run;

This will produce the following table:

 

Capture23Sep17.JPG

It would be helpful if XYZm inherited all of the attributes of XYZ.

 

Hope that clarifies.

by Super User
on ‎09-23-2017 01:39 PM

That would be extremely hard to do. What syntax would you propose that SAS could recognize that you wanted this new behavior?  You couldn't modify how SAS handles a simple assignment statement as that would break zillions of lines of existing code that depend on the current behavior.

 

To copy type/length/format/informat/label just read the variable twice using RENAME= dataset option.

data want ;
  set have ;
  set have (keep=XYZ rename=(XYZ=XYZm));
  XYZm = ....;
run;
by Frequent Contributor
on ‎09-23-2017 01:43 PM

I was proposing a new function: inherit

 

XYZm = inherit(XYZ) ;

 

However, your solution looks good. I'll try it!

Idea Statuses
Top Liked Authors