BookmarkSubscribeRSS Feed
Cuneyt
Obsidian | Level 7

Dear All,

I am trying to import a "|" delimited text file without much success. The data set has many character variables of variable length. I am not getting any error messages, but SAS reads many variables in correctly. The SAS code, input file and output data set are shown below. Any help will be greatly appreciated.

data WORK.IMPORT;
	infile "/home/c.eroglu/fec/k.txt" delimiter = '|' firstobs=1 missover;
	input	cmte_id			$ /* max length = 9   */ 
			amndt_ind		$ /* max length = 1   */
			rpt_tp			$ /* max length = 3   */
			transaction_pgi	$ /* max length = 5   */
			image_num		$ /* max length = 18  */
			transaction_tp	$ /* max length = 3   */
			entity_tp		$ /* max length = 3   */
			name			$ /* max length = 200 */
			city			$ /* max length = 30  */
			state			$ /* max length = 2   */
			zip_code		$ /* max length = 9   */
			employer		$ /* max length = 38  */
			occupation		$ /* max length = 38  */
			transaction_dt	$ /* max length = 8   */
			transaction_amt	 
			other_id		$ /* max length = 9   */
			tran_id			$ /* max length = 12  */
			file_num		
			memo_cd			$ /* max length = 1   */
			memo_text		$ /* max length = 100 */
			sub_id			;
 run;

Cuneyt_0-1723158908270.png

 

2 REPLIES 2
Ksharp
Super User
data WORK.IMPORT;
	infile "c:\temp\k.txt" delimiter = '|' dsd truncover;
	input	cmte_id			$ /* max length = 9   */ 
			amndt_ind		$ /* max length = 1   */
			rpt_tp			$ /* max length = 3   */
			transaction_pgi	$ /* max length = 5   */
			image_num		$ /* max length = 18  */
			transaction_tp	$ /* max length = 3   */
			entity_tp		$ /* max length = 3   */
			name			$ /* max length = 200 */
			city			$ /* max length = 30  */
			state			$ /* max length = 2   */
			zip_code		$ /* max length = 9   */
			employer		$ /* max length = 38  */
			occupation		$ /* max length = 38  */
			transaction_dt	$ /* max length = 8   */
			transaction_amt	 
			other_id		$ /* max length = 9   */
			tran_id			$ /* max length = 12  */
			file_num		
			memo_cd			$ /* max length = 1   */
			memo_text		$ /* max length = 100 */
			sub_id			;
 run;
Cuneyt
Obsidian | Level 7

Here is the solution that worked for me:

data WORK.IMPORT;
    infile "/home/c.eroglu/fec/k.txt" delimiter = '|' firstobs=1 missover dsd;
    length cmte_id          $9. 
            amndt_ind       $1. 
            rpt_tp          $3. 
            transaction_pgi $5. 
            image_num       $18.
            transaction_tp  $3. 
            entity_tp       $3. 
            name            $200. 
            city            $30. 
            state           $2. 
            zip_code        $9. 
            employer        $38.
            occupation      $38.
            transaction_dt  $8. 
            transaction_amt  8.
            other_id        $9. 
            tran_id         $12. 
            file_num        $22.
            memo_cd         $1.  
            memo_text       $100.
            sub_id          $19.;
           
           
           
    input cmte_id           $ 
            amndt_ind       $ 
            rpt_tp          $ 
            transaction_pgi $ 
            image_num       $ 
            transaction_tp  $ 
            entity_tp       $ 
            name            $ 
            city            $ 
            state           $ 
            zip_code        $ 
            employer        $ 
            occupation      $ 
            transaction_dt  $ 
            transaction_amt  
            other_id        $ 
            tran_id         $ 
            file_num        $
            memo_cd         $ 
            memo_text       $ 
            sub_id          $;
 run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 2 replies
  • 828 views
  • 1 like
  • 2 in conversation