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

data bank2;
infile datalines dsd;
input name $ rate;
datalines;
FirstCapital 0.0718
DirectBank 0.0721
VirtualDirect 0.0728
;
run;
proc print data = bank2;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Your sample program is most of the solution.  However, by reading across from left to right and taking whatever is found in the data, the program has to decide how many characters to use to store NAME.  In that situation, the software automatically uses a length of 8, so values of NAME will be truncated.  To fix that, define NAME before the INPUT statement:

data bank2;
infile datalines dsd;
length name $ 15;
input name $ rate;
datalines;
FirstCapital 0.0718
DirectBank 0.0721
VirtualDirect 0.0728
;

Just select a length that makes sense for the data you need to read.

 

Also note, if some values of NAME contain an embedded blank such as "First Capital", you will need to take additional steps.

View solution in original post

4 REPLIES 4
jimbarbour
Meteorite | Level 14
I don't understand. What ate you asking?

If you are getting errors, please post your log.

Jim
tianerhu
Pyrite | Level 9
I want to make a SAS data set using datalines statement ,the data in the datalines as following:

FirstCapital 0.0718
DirectBank 0.0721
VirtualDirect 0.0728

the variable name is 'name' and 'rate' .
Astounding
PROC Star

Your sample program is most of the solution.  However, by reading across from left to right and taking whatever is found in the data, the program has to decide how many characters to use to store NAME.  In that situation, the software automatically uses a length of 8, so values of NAME will be truncated.  To fix that, define NAME before the INPUT statement:

data bank2;
infile datalines dsd;
length name $ 15;
input name $ rate;
datalines;
FirstCapital 0.0718
DirectBank 0.0721
VirtualDirect 0.0728
;

Just select a length that makes sense for the data you need to read.

 

Also note, if some values of NAME contain an embedded blank such as "First Capital", you will need to take additional steps.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 661 views
  • 1 like
  • 3 in conversation