BookmarkSubscribeRSS Feed
cjohnson
Obsidian | Level 7
I am trying to import data from a text file, and I need to keep the leading blanks. Here is what I am using:

@0021 SubmissionRecordCount $CHAR8.

Data is:

SC010024201103241201 1468

However, even with the CHAR informat, it still loses the blanks.

I would appreciate any help!

Thanks,
Chris
Christopher Johnson
www.codeitmagazine.com
5 REPLIES 5
Benjy
Calcite | Level 5
One way of looking at the problem is that you're not losing the blanks, you are just left aligning your character variable. So right align it and add blanks. The RIGHT function will right-align the variable when output.
data_null__
Jade | Level 19
Your code is working exactly as expected. You can use the justification format modifier to right justify the value in the field.

[pre]
80 data _null_;
81 length SubmissionRecordCount $8;
82 input @0021 SubmissionRecordCount $CHAR8.-R;
83 put '12345678';
84 put (S:) ($char20.);
85 cards;

12345678
1468
[/pre]

If you change the variable length the justifcation is unexpected.

[pre]
data _null_;
length SubmissionRecordCount $20;
input @0021 SubmissionRecordCount $CHAR8.-R;
put '12345678901234567890';
put (S:) ($char20.);
cards;
SC010024201103241201 1468
;;;;
run;[/pre]

[pre]
125 data _null_;
126 length SubmissionRecordCount $20;
127 input @0021 SubmissionRecordCount $CHAR8.-R;
128 put '12345678901234567890';
129 put (S:) ($char20.);
130 cards;

12345678901234567890
1468
[/pre]
Doc_Duke
Rhodochrosite | Level 12
I took data_null_'s code and dropped the "-R" and got what I think that cjohnson is looking for. (SAS 9.2 TS2M3).

cjohnson, If you are still having problems, maybe you can explain more fully. Another way to debug this is to print the data with the hex format so you can precisely tell what is in there.

Doc Muhlbaier
Duke

data _null_;
length SubmissionRecordCount $20;
input @0021 SubmissionRecordCount $CHAR8.;
put '12345678901234567890';
put (S:) ($char20.);
cards;
SC010024201103241201 1468
;;;;
run;

10 data _null_;
11 length SubmissionRecordCount $20;
12 input @0021 SubmissionRecordCount $CHAR8.;
13 put '12345678901234567890';
14 put (S:) ($char20.);
15 cards;

12345678901234567890
1468
chang_y_chung_hotmail_com
Obsidian | Level 7
The leading blanks are preserved if you use $char informat. Here is an example run on my 9.2 (TS1M0), windows platform:



data one;

  input @21 count $char8.;

cards;

----+----1----+----2----+----3

SC010024201103241201 1468

;

run;

proc print data=one;

run;

/* on lst

Obs    count

 1     ----+---

 2      1468

*/
cjohnson
Obsidian | Level 7
Ah...you are right. The leading blanks were being preserved. I couldn't see it in the table view, but when I also added the $char format to the export, it kept the blanks. Thanks very much!
Christopher Johnson
www.codeitmagazine.com

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
  • 5 replies
  • 1357 views
  • 0 likes
  • 5 in conversation