If your number is 25 you'll have to divide it by 100 first, either in your import or a separate data step.
Data sample;
Input value;
Value_fract=value/100;
Format value_fract fract8.;
Cards;
25
33
45
67
;
Run;
Thanks Reeza.
This did not work.
data dm.timeseries_1;
input international_students;
international_students_fract = international_students/100;
format international_students_fract fract8.;
run;
I simply tried this and it did work:
data dm.timeseries_1;
set dm.timeseries;
international_students_fract = international_students/100;
format international_students_fract fract8.;
run;
But the still my issue remains, converting a number into it's fraction in the same column itself.
Does my sample code work?
Show the actual input values, the actual output values, the desired output and describe exactly how it "doesn't work": no output, incorrect output, close but not quite what is wanted.
And run PROC contents on your data set and show the results.
@Antaralib wrote:
But the still my issue remains, converting a number into it's fraction in the same column itself.
I don't know what doesn't work means.
If you want it in the same column then divide the value by 100 and apply the format to the variable - using the same name. Or write a custom format, but I wouldn't recommend that.
data dm.timeseries_1;
set dm.timeseries;
international_students = international_students/100;
format international_students fract8.;
run;
The sample you provided did not work. I used the code to divide the value by 100. But nothing happened.
Actual input:
data dm.timeseries_1;
input international_students;
international_students_fract = international_students/100;
format international_students_fract fract8.;
run;
I run the code above, and view the table. NO changes applied.
Proc contents:
The CONTENTS Procedure
Data Set Name DM.TIMESERIES_1 Observations 2603
Member Type DATA Variables 15
Engine V9 Indexes 0
Created Wednesday, April 13, 2005 12:00:00 AM Observation Length 200
Last Modified Wednesday, April 13, 2005 12:00:00 AM Deleted Observations 0
Protection Compressed NO
Data Set Type Sorted NO
Label
Data Representation WINDOWS_32
Encoding wlatin1 Western (Windows)
Engine/Host Dependent Information
Data Set Page Size 16384
Number of Data Set Pages 33
First Data Page 1
Max Obs per Page 81
Obs in First Data Page 68
Number of Data Set Repairs 0
File Name C:\Documents and Settings\STD\My Documents\Antara\DM\timeseries_1.sas7bdat
Release Created 9.0101M3
Host Created XP_PRO
Alphabetic List of Variables and Attributes
# Variable Type Len Format Informat
7 citations Num 8 BEST12. BEST32.
3 country Char 24 $24. $24.
13 female_male_ratio Char 9 $9. $9.
8 income Char 7 $7. $7.
5 international Char 5 $5. $5.
12 international_students Num 8 COMMA12. COMMA32.
15 international_students_fract Num 8 FRACT8.
10 num_students Char 8 $8. $8.
6 research Num 8 BEST12. BEST32.
11 student_staff_ratio Num 8 BEST12. BEST32.
4 teaching Num 8 BEST12. BEST32.
9 total_score Num 8 BEST12. BEST32.
2 university_name Char 73 $73. $73.
==============================
I also tried the folowing codes:
1) data _null_;
internationl_Students = '25%';
internationl_Students2 = input(international_Students,FRACT2.);
2)proc datasets lib=dm nolist;
modify timeseries_1;
format international_Students PERCENT2.;
run;
3)
proc datasets lib=dm nolist;
modify timeseries_1;
format international_Students PERCENTN.;
run;
NOne of these worked either.
This doesn't work?
Data sample;
Input value;
Value_fract=value/100;
Format value_fract fract8.;
Cards;
25
33
45
67
;
Run;
proc print data=sample;
run;
I get the following:
The SAS System 09:33 Monday, April 25, 2016 52
Value_
Obs value fract
1 25 1/4
2 33 33/100
3 45 9/20
4 67 67/100
I think I'm at the point where you're doing something really wrong. Or we're not understanding what you want.
Your dataset and proc contents shows its fine.
Please post the output from the following code:
data dm.timeseries_1;
input international_students;
international_students_fract = international_students/100;
format international_students_fract fract8.;
run;
proc print data=dm.timeseries_1 (obs=5) label;
var international_students internation_students_fract;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.