BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
maroulator
Obsidian | Level 7

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; 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

1 REPLY 1
ballardw
Super User

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.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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