BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
EliajhBazarski
Fluorite | Level 6
I set dataset with var A only integer: 1 3 4
And set dataset with var A 1.1 2.1 2.2;

After setting together my integer values 1 3 4 turns to 1.0 3.0 4.0. Are any logical errors there, options to fix it in SAS Base?
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

@EliajhBazarski wrote:
Hi, thanks. I used format informat _all_. Only Result Viewer displays this, but viewtable not. Maybe, problem with SAS settings?

Nothing is wrong.

I assume by "Result Viewer" you mean the output of some procedure.  Which procedure?  Is it PROC PRINT?

If you don't give PROC PRINT a specific format to use it will try its best to make a nice output.

Experiment.

data test;
  input x @@;
cards;
1 2 3 4 1.1 1.2 1.1234
;
proc print data=test;
run;
proc print data=test;
 where x=int(x);
run;
proc print data=test;
  format x 4.1;
run;
Obs       x

 1     1.0000
 2     2.0000
 3     3.0000
 4     4.0000
 5     1.1000
 6     1.2000
 7     1.1234

Obs    x

 1     1
 2     2
 3     3
 4     4

Obs       x

 1      1.0
 2      2.0
 3      3.0
 4      4.0
 5      1.1
 6      1.2
 7      1.1

View solution in original post

7 REPLIES 7
Tom
Super User Tom
Super User

@EliajhBazarski wrote:
I set dataset with var A only integer: 1 3 4
And set dataset with var A 1.1 2.1 2.2;

After setting together my integer values 1 3 4 turns to 1.0 3.0 4.0. Are any logical errors there, options to fix it in SAS Base?

Numbers are numbers.  There is no difference between 1 and 1.0 or for that matter 00001 and 1.00000.  It is all the number one.

 

Most likely the reason is that the other dataset is using a different FORMAT to display the values. When you combine two or more dataset that have the same variable the first format the data step compiler sees is the one that is used.  So if the first dataset in the SET statement did no have any special format attached to the variable and the second one did then that is the format that will be attached to the variable in the new dataset.

 

Or it is just that it is displaying the values for the variable with a consistent number of decimal places across all observations.  And now that some of the values are non-integers it is displaying the decimal places for all of the values.

EliajhBazarski
Fluorite | Level 6
Hi, thanks a lot! You upgrade my knowledge in SAS.
It's weird problem, because I use format informat _all_. When I watch it from Viewtable there is no problem, only Resultviewer do it🤷
Ksharp
Super User
I guess that It is because var A in the first dataset have a different format with the second dataset.
Try
format A best.;
after setting together .
EliajhBazarski
Fluorite | Level 6
Hi, thanks. I used format informat _all_. Only Result Viewer displays this, but viewtable not. Maybe, problem with SAS settings?
Tom
Super User Tom
Super User

@EliajhBazarski wrote:
Hi, thanks. I used format informat _all_. Only Result Viewer displays this, but viewtable not. Maybe, problem with SAS settings?

Nothing is wrong.

I assume by "Result Viewer" you mean the output of some procedure.  Which procedure?  Is it PROC PRINT?

If you don't give PROC PRINT a specific format to use it will try its best to make a nice output.

Experiment.

data test;
  input x @@;
cards;
1 2 3 4 1.1 1.2 1.1234
;
proc print data=test;
run;
proc print data=test;
 where x=int(x);
run;
proc print data=test;
  format x 4.1;
run;
Obs       x

 1     1.0000
 2     2.0000
 3     3.0000
 4     4.0000
 5     1.1000
 6     1.2000
 7     1.1234

Obs    x

 1     1
 2     2
 3     3
 4     4

Obs       x

 1      1.0
 2      2.0
 3      3.0
 4      4.0
 5      1.1
 6      1.2
 7      1.1
EliajhBazarski
Fluorite | Level 6
Thank you!! It is only nice output with proc print. No problem) I am grateful for you!

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 538 views
  • 6 likes
  • 4 in conversation