DATA Step, Macro, Functions and more

import percent values

Accepted Solution Solved
Reply
Contributor
Posts: 28
Accepted Solution

import percent values

Hi, i have data in .csv file. i am unable to read percent variables into sas enterprise guide. percent variables values are like 98%,92%. i tried percent6. in length and input statements but still percent values are not being read. i am using infile statement to import the file to sas. please help me.Thanks in advance.


Accepted Solutions
Solution
Wednesday
Super User
Super User
Posts: 8,070

Re: import percent values

Posted in reply to VISHNU239

@VISHNU239 wrote:

Hi, i have data in .csv file. i am unable to read percent variables into sas enterprise guide. percent variables values are like 98%,92%. i tried percent6. in length and input statements but still percent values are not being read. i am using infile statement to import the file to sas. please help me.Thanks in advance.


You can use the PERCENT informat to read text strings that have %.  You can use the PERCENT format to display values with %.

data want ;
  input p :percent. ;
  format p percent. ;
cards;
98%
.98
50%
0.5
;
proc print;
run;

image.png

View solution in original post


All Replies
PROC Star
Posts: 1,265

Re: import percent values

Posted in reply to VISHNU239

Show us your code Smiley Happy

Contributor
Posts: 28

Re: import percent values

data abc;

infile "file path" dsd dlm=',' firstobs=2 missover;

length target_percent percent6.;

input target_percent;

run;

 

input file has target_percent values as 98%. i need to read 98% into target_percent in sas and it should be displayed as 98% in sas.Thank you.

PROC Star
Posts: 1,769

Re: import percent values

[ Edited ]
Posted in reply to VISHNU239

informat can't be in length stmt

try

data abc;

infile "file path" dsd dlm=',' firstobs=2 missover;

input target_percent :  percent6. ;

run

 

 

or

 

data abc;

infile "file path" dsd dlm=',' firstobs=2 missover;

informat target_percent percent6. ;

input target_percent;

run;

Solution
Wednesday
Super User
Super User
Posts: 8,070

Re: import percent values

Posted in reply to VISHNU239

@VISHNU239 wrote:

Hi, i have data in .csv file. i am unable to read percent variables into sas enterprise guide. percent variables values are like 98%,92%. i tried percent6. in length and input statements but still percent values are not being read. i am using infile statement to import the file to sas. please help me.Thanks in advance.


You can use the PERCENT informat to read text strings that have %.  You can use the PERCENT format to display values with %.

data want ;
  input p :percent. ;
  format p percent. ;
cards;
98%
.98
50%
0.5
;
proc print;
run;

image.png

Contributor
Posts: 28

Re: import percent values

[ Edited ]

Hi, Tom.

 

I changed the code to this way

 

data abc;

infile "file path" dsd dlm=',' firstobs=2 missover;

length target_percent 8. ;

input target_percent   Smiley Tongueercent. ;

run;

 

 

In the output of sas the percent values are being displayed as .50 instead of 50%. Any other suggestions. Your suggestion worked for calculation part but for the display it is showing as .50 instead of 50%. Thank you.

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 114 views
  • 1 like
  • 4 in conversation