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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

@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

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Show us your code 🙂

VISHNU239
Obsidian | Level 7

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.

novinosrin
Tourmaline | Level 20

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;

Tom
Super User Tom
Super User

@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

VISHNU239
Obsidian | Level 7

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   :percent. ;

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 4200 views
  • 2 likes
  • 4 in conversation