- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have a code like this
Jadhav, Rakesh 1234 123 Sales 43,696.78 Bhate, Sameer 1240 132 Sales 45,099.50 Rane, Dipak 1252 133 SALES 47,098.71 Patil, Chetan 1424 105 Marketing 17,098.71 Khan, Salama 1366 122 Publications 29,996.63 Shete, Vinod 1004 101 Education 31,875.46 Konde, Neel 1112 109 Marketing 31,875.46 Shevate, Sunil 1532 101 Education 25,309.00 Jordan, Vicky 1144 101 Education 38,309.00 Lande, Prakash 1084 105 Marketing 28,567.23 Kale, Pravin 1442 112 Publications 38,945.89 Mane, Atish 1331 109 Research 57,354.56 Reeves, Neal 1255 109 Research 46,180.00
i want the data appear to be like this
Obs lastname firstname deptid salary 1 Jadhav Rakesh 123 43,696.78 2 Bhate Sameer 132 45,099.50 3 Rane Dipak 133 47,098.71 4 Patil Chetan 105 17,098.71 5 Khan Salama 122 29,996.63 6 Shete Vinod 101 31,875.46 7 Konde Neel 109 31,875.46 8 Shevate Sunil 101 25,309.00 9 Jordan Vicky 101 38,309.00 10 Lande Prakash 105 28,567.23 11 Kale Pravin 112 38,945.89 12 Mane Atish 109 57,354.56 13 Reeves Neal 109 46,180.00
how can i read this data, using infile statement?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
https://stats.idre.ucla.edu/sas/code/reading-a-multiple-line-per-subject-data-file/
* 2 lines of data per subject;
data temp;
input a b c / d e f;
cards;
1 2 3
4 5 6
1 3 5
2 4 6
;
run;
proc print data = temp;
run;
Obs a b c d e f
1 1 2 3 4 5 6
2 1 3 5 2 4 6
* three lines of data per subject;
data temp2;
input #1 a b #2 c d #3 e f;
cards;
1 2
3 4
5 6
1 3
5 2
4 6
9 8
7 6
5 4
;
run;
proc print data = temp2;
run;
Obs a b c d e f
1 1 2 3 4 5 6
2 1 3 5 2 4 6
3 9 8 7 6 5 4
* example reading in a file;
* this example assumes that you have saved this data set as a text file in "C:multiple_line.txt";
100010133346851 1 1330 7954140200 5069
1000102 201 7 * 2 2 2 * 4 4 8 8 8 john
1000103 5- - 533
1000104 59 2 633
1000105 5- - 522
1000106 222222222222
1000107 34
1000108 2336
1000109 2336
1000110 2555
1000111 400 2
100020113226652 1 1 1340 7952140200 5069
1000202 101 7 * * * * 6 * 7 7 carl
1000203 2 1 4 2 1 431401
1000204 2 1 4 2 1 432404
1000205 5- 3 622
1000206 543343442243
1000207 44
1000208 122
1000209 1223
1000210 2555
1000211 260
data temp3;
infile 'c:multiple_line.txt' missover lrecl=100;
input id 1-5 line 6-7 v1 8-15 #2 v2 19-21 v3 $ 58-59 v4 $ 79-83 #3 v5 20 #11 v6 20-24;
run;
proc print data= temp3;
run;
Obs id line v1 v2 v3 v4 v5 v6
1 10001 1 33346851 201 2 john 5 400
2 10002 1 13226652 101 carl 2 260
@Raj00007 wrote:
I have a code like this
Jadhav, Rakesh 1234 123 Sales 43,696.78 Bhate, Sameer 1240 132 Sales 45,099.50 Rane, Dipak 1252 133 SALES 47,098.71 Patil, Chetan 1424 105 Marketing 17,098.71 Khan, Salama 1366 122 Publications 29,996.63 Shete, Vinod 1004 101 Education 31,875.46 Konde, Neel 1112 109 Marketing 31,875.46 Shevate, Sunil 1532 101 Education 25,309.00 Jordan, Vicky 1144 101 Education 38,309.00 Lande, Prakash 1084 105 Marketing 28,567.23 Kale, Pravin 1442 112 Publications 38,945.89 Mane, Atish 1331 109 Research 57,354.56 Reeves, Neal 1255 109 Research 46,180.00i want the data appear to be like this
Obs lastname firstname deptid salary 1 Jadhav Rakesh 123 43,696.78 2 Bhate Sameer 132 45,099.50 3 Rane Dipak 133 47,098.71 4 Patil Chetan 105 17,098.71 5 Khan Salama 122 29,996.63 6 Shete Vinod 101 31,875.46 7 Konde Neel 109 31,875.46 8 Shevate Sunil 101 25,309.00 9 Jordan Vicky 101 38,309.00 10 Lande Prakash 105 28,567.23 11 Kale Pravin 112 38,945.89 12 Mane Atish 109 57,354.56 13 Reeves Neal 109 46,180.00how can i read this data, using infile statement?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This seems to work:
data example; infile datalines; input lastname :$10. firstname :$10. / deptid /salary :comma10. ; lastname = compress(lastname,','); format salary comma12.2; datalines; Jadhav, Rakesh 1234 123 Sales 43,696.78 Bhate, Sameer 1240 132 Sales 45,099.50 Rane, Dipak 1252 133 SALES 47,098.71 Patil, Chetan 1424 105 Marketing 17,098.71 Khan, Salama 1366 122 Publications 29,996.63 ;
You would use an INFILE statement that points to your file and not include the DATALINES. You may want different informats for the names if you have longer actual names. This likely won't work for names with 3 or more parts.
The / in the INPUT statement basically says "read from next line".
If any of your data per person is more or less than 3 lines then this also will fail because it doesn't match the example shown.
You did not indicate whether the deptid should be character or numeric.