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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1097 views
  • 0 likes
  • 5 in conversation