Good morning,
My data has this variable AZI_MIC_DD in character format and and length is $21, i need it to be in numeric and in length 8.
i used this coded
DATA Marchsub.Lab1718_A(DROP=DOB_LAB);
SET Marchsub.Lab1718;
AZIMIC_DD =INPUT(AZI_MIC_DD, BEST12.);
DROP AZI_MIC_DD;
RENAME AZIMIC_DD=AZI_MIC_DD;
RUN;
Is there anything wrong with this code?
@Dhana18 wrote:
so after i ma done fixing the length and the format i need to match with the master provided using this code
options nofmterr;
data marchsub.MIL_lab_2018_YE;;
set mstruct.master_lab Marchsub.Lab1718_C;
run;
after i used this code, values in the variables AZI_MIC_DD changes from 0.125 to 0. which is
inaccurate
The set statement above is use the properties of variables as defined in the mstruct.master_lab data set. So if the format for a variable is set not to display any decimal portion in the first set it by default does not appear after the data is appended.
data work.set1; input x; format x f3.; datalines; 1 22 333 ; run; data work.set2; input x; format x best12.; datalines; .1111111 .222222222 .3333333333 ; run; data work.example; set work.set1 work.set2; run;
Which by default will show the decimals from work.set2 as 0 because of the now default format of F3.
However, unless you have done something explicitly to the values the value did not change. You just need to set the format to display enough decimals. F18.12 and others would also show more digits.
proc print data=work.example; format x best18.; run;
Do you get errors when you run the code? If so, please show us the entire SAS log, pasted into the window that appears when you click on the {i} icon.
Is the result not what you expect? Please explain, show us a portion of the input data and the output.
@Dhana18 wrote:
NOTE: There were 6642 observations read from the data set MARCHSUB.LAB1718_B.
NOTE: The data set MARCHSUB.LAB1718_C has 6642 observations and 29 variables.
NOTE: DATA statement used (Total process time):
real time 0.20 seconds
cpu time 0.09 seconds
This would indicate that the program worked properly!
@Dhana18 wrote:
so after i ma done fixing the length and the format i need to match with the master provided using this code
options nofmterr;
data marchsub.MIL_lab_2018_YE;;
set mstruct.master_lab Marchsub.Lab1718_C;
run;
after i used this code, values in the variables AZI_MIC_DD changes from 0.125 to 0. which is
inaccurate
Then you need to supply example data in a form that leaves no room for ambiguities (data step with datalines).
@Dhana18 wrote:
Can you explain to me please I did not understand what you are saying
Then you need to supply example data in a form that leaves no room for ambiguities (data step with datalines).
@ballardw has just given you examples for this. Creation of made-up data by using datasteps with datalines is an essential SAS skill IMO.
@Dhana18 wrote:
so after i ma done fixing the length and the format i need to match with the master provided using this code
options nofmterr;
data marchsub.MIL_lab_2018_YE;;
set mstruct.master_lab Marchsub.Lab1718_C;
run;
after i used this code, values in the variables AZI_MIC_DD changes from 0.125 to 0. which is
inaccurate
The set statement above is use the properties of variables as defined in the mstruct.master_lab data set. So if the format for a variable is set not to display any decimal portion in the first set it by default does not appear after the data is appended.
data work.set1; input x; format x f3.; datalines; 1 22 333 ; run; data work.set2; input x; format x best12.; datalines; .1111111 .222222222 .3333333333 ; run; data work.example; set work.set1 work.set2; run;
Which by default will show the decimals from work.set2 as 0 because of the now default format of F3.
However, unless you have done something explicitly to the values the value did not change. You just need to set the format to display enough decimals. F18.12 and others would also show more digits.
proc print data=work.example; format x best18.; run;
@Dhana18 wrote:
the for mat has to be like this F_AZIMIC_DD.
You need to provide the PROC Format code that defines the format if that is a custom format.
If you want to show decimals and the current format does not allow that then you need to modify the format or bring the problem to whoever created or indicated that format needs to be used.
If you only need to display the decimals when the integer portion of the value is between 0 and 1 that may be a range definition issue in the proc format code.
The ultimate judgement will always be a test. So apply Maxim 4.
What strikes me is that you said the character variable has a length of 21, but you only use a 12-character informat. Why don't you use best21.?
Nothing major. I only see two issues. Only the first one might cause issues as it might generate the wrong number from long strings since it will only read the first 12 characters.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.