1 new york 7,262,700
2 los angeles 3,259,340
3 philadelphia 1,642,900
how to read the above data using input statement
consider the above data is in txt format externally
u have to use infile and input statement.
Answers were Sorted based on User's Feedback
Answer / subbu
data s;
input no 1-2 area $ 3-15 am $ 16-30 ;
amount=input(am,comma15.);
format amount comma15.;
drop am;
cards;
1 new york 7,262,700
2 los angeles 3,259,340
3 philadelphia 1,642,900
;
proc print;
run;
Is This Answer Correct ? | 4 Yes | 0 No |
Answer / pravin
data cityrank;
input rank @3 city $ 13. amount : comma15.;
datalines;
1 new york 7,262,700
2 los angeles 3,259,340
3 philadelphia 1,642,900
;
run;
proc print data=cityrank;
run;
this is the ans only for this example new york has more than
single blank so problem arise hire.if not & modifier can be
used.
Is This Answer Correct ? | 3 Yes | 3 No |
Answer / chandrakanth
To Solasa and others ....whenever you read data from an input file...you need to be careful about the last data value in every dataline you have values like x,xxx,xxx which is total width of 9, when you mention more than 9 the input pointer will go the next data line to get the remaining spaces. So in your code you used comma10. try with using comma9. I am very sure it will work.
Another option is if you want to keep that comma10. use TRUNCOVER in the infile statement, this should fix all the extra spaces you mention in the input statement.
let me know if this does not help you
Is This Answer Correct ? | 0 Yes | 2 No |
Answer / poornima
data poo;
infile 'D:\poo.txt ';
input rank country $ 12. salary ;
INFORMAT SALARY COMMA10.;
FORMAT SALARY COMMA10.;
run;
proc print;
run;
Is This Answer Correct ? | 0 Yes | 2 No |
Answer / guest
data temp;
infile datalines ;
input sno city & $12.
pop : comma.;
datalines;
1 new york 7,262,700
2 los angeles 3,259,340
3 philadelphia 1,642,900
;
The ampersand (&) modifier is used to read character values
that contain embedded blanks.
The colon (:) modifier is used to read nonstandard data
values and character values that are longer than eight
characters, but which contain no embedded blanks.
Is This Answer Correct ? | 0 Yes | 3 No |
Answer / guest
data temp;
infile datalines ;
input sno city & $12.
pop : comma.;
datalines;
1 new york 7,262,700
2 los angeles 3,259,340
3 philadelphia 1,642,900
;
The ampersand (&) modifier is used to read character values
that contain embedded blanks.
The colon (:) modifier is used to read nonstandard data
values and character values that are longer than eight
characters, but which contain no embedded blanks.
Is This Answer Correct ? | 1 Yes | 4 No |
Differentiate between proc means and proc summary.
The below code we are using for creating more than one macro variables in proc sql using into clause. How we can use same code to create macro variables vara, varb, varc instead of var1, var2, var3.? proc sql noprint; select count(distinct(patient)) into :var1 - :var3 from dataset1 group by trtreg1c ; quit;
Explain what is SAS informats?
If you have a dataset that contains 100 variables, but you need only five of those, what is the code to force SAS to use only those variables?
how do we get duplicate observations in a separate dataset?
Which is the best place to learn SAS clinicals and Oracle clinical in hyderabad?
what is Global Symbol table and Local symbol table?
How to read multiple excel sheets from a single excel file at once????
7 Answers HCL, Verinon Technology Solutions,
what is the difference between compiler and interpreter? give any one example (software product) that act as a interpreter?
36 Answers Accenture, College School Exams Tests, CTS, IBM, IHRD, Infosys, Sylhet Engineering College, TCS, Wipro,
HOW DO WE CREATE A SAS STORED PROCESS IN SAS EG ?
What is a put statement?
Give an example where SAS fails to convert character value to numeric value automatically?