Truncated Observations

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 121
Accepted Solution

Truncated Observations

To whom it may concern,

Below is the code that I've been running on the 'example' dataset that is generated once I read the attached .txt file into SAS; my goal is to generate datasets hpi1 and hpi2. My problem is that after generating hpi1, the values of my observations seem to become rounded (which I don't want; I want the full number of decimal digits from the original variable in the example dataset) and when I try generating hpi2, I get no values for my variables whatsoever. I've tried the LENGTH and FORMAT statement, but I seem to be missing somthing simple.

Reading .txt file into SAS:

data example;
  infile '/folders/example.txt' dlm='090D'x LRecL=10000;
  input location $2. month1-month15;
  format month1-month15 best15.12;
run;

options mprint mlogic symbolgen;

%let arrlowbound=1;

        %macro test();
          %let arrelements=15;
          %let arrupbound=%eval(&arrlowbound+14);
          array month{&arrelements} month&arrlowbound-month&arrupbound;
          format month&arrlowbound-month&arrupbound
            %let increment=%eval(&arrlowbound+2);
            drop month&arrlowbound-month&increment;
               %let No1=%eval(&arrupbound+1);
               %let No2=%eval(&arrupbound+2);
               %let No3=%eval(&arrupbound+3);
               month&No1=month(&arrupbound);
               month&No2=month(&arrupbound);
               month&No3=month(&arrupbound);
               output;
         %mend test;

***************************************I THINK THAT MY PROBLEMS BEGIN FROM HERE ON DOWN ******************************

data hpi1;
    set example;    
         %test;
run;

data hpi2; 
    set hpi1;
    %let arrlowbound=%eval(&arrlowbound+3);     
    %test();
run; 

Attachment

Accepted Solutions
Solution
‎06-11-2014 01:17 PM
Super User
Posts: 10,500

Re: Truncated Observations

The values are not truncated but the display format may make them appear that way. Also SAS has no way of knowing by default that trailing zeros on decimals are significant.

Assign a format such as f16.12 so that the number of digits you want will always appear for those variables. You can do that in your read program with:

Format Month: f16.12;

You may need to make additional format assignments for other variables created from these if you want a similar behavior.

If you run Proc Contents or use the SAS expolorer to look at the data the variables most likely have a format of BESTXX. , xx may vary. By default the BEST formats will not display the trailing decimals, the W.D of Fw.d format will display the number of decimal places indicated by the D value.

View solution in original post


All Replies
Solution
‎06-11-2014 01:17 PM
Super User
Posts: 10,500

Re: Truncated Observations

The values are not truncated but the display format may make them appear that way. Also SAS has no way of knowing by default that trailing zeros on decimals are significant.

Assign a format such as f16.12 so that the number of digits you want will always appear for those variables. You can do that in your read program with:

Format Month: f16.12;

You may need to make additional format assignments for other variables created from these if you want a similar behavior.

If you run Proc Contents or use the SAS expolorer to look at the data the variables most likely have a format of BESTXX. , xx may vary. By default the BEST formats will not display the trailing decimals, the W.D of Fw.d format will display the number of decimal places indicated by the D value.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 185 views
  • 1 like
  • 2 in conversation