BookmarkSubscribeRSS Feed
littlestone
Fluorite | Level 6
suppose I have following data:


blank 1 1 1
2 blank 2 2
3 3 blank 3
4 4 4 blank


The delimiter is a blank (" "). And the missing value is also denoted as a blank(i.e. " ". I type "blank" in the data just to clarify).

what input code can work for such data?
thanks.
8 REPLIES 8
Ksharp
Super User
Hi.
That column input method would be used.
[pre]
data temp;
input a 1 b 3 c 5 d 7;
cards;
1 1 1
2 2 2
3 3 3
4 4 4
;run;
[/pre]




Ksharp
littlestone
Fluorite | Level 6
Thank you for reply. However, what if raw data look like this:

blank 1 1 1
2 blank 22 2
3 333 blank 3
4444 4 4 blank
Patrick
Opal | Level 21
Something like below could work:

data test;
infile datalines dsd delimiter='|' truncover;
input @;
_infile_=tranwrd(trim(_infile_),' ','|');
_infile_=tranwrd(trim(_infile_),' ','|');
input a b c d;
put a= b= c= d=;
datalines;
blank 1 1 1
2 blank blank 2
3 333 blank 3
4444 4 4 blank
;
run;

...or even so (the left over blanks have now only the meaning of "delimiter"):

data test;
infile datalines dsd delimiter='| ' truncover;
input @;
_infile_=tranwrd(trim(_infile_),' ','|');
input a b c d;
put a= b= c= d=;
datalines;
blank 1 1 1
2 blank blank 2
3 333 blank 3
4444 4 4 blank
;
run;

HTH
Patrick Message was edited by: Patrick
art297
Opal | Level 21
I would try:


data test;
infile datalines dsd delimiter='|' truncover;
length x $40;
input @;
_infile_=tranwrd(_infile_,' ','|');
_infile_=tranwrd(_infile_,' ','|');
input a b c d;
datalines;
1 1 1
2 2
3 333 3
4444 4 4
;
run;

HTH,
Art
Peter_C
Rhodochrosite | Level 12
the only problem seems to be that a blank item has space for itself on the input line as well as the delimiter and DSD infile option considers consecutive delimiters imply an empty item. So just reduce two blanks to one. This is very similar to earlier posts, but uses only one tranwrd().[pre]data test ;
infile datalines dsd delimiter=' ' truncover;
input @ ;
_infile_= tranwrd( _infile_,' ',' ' );
input a b c d;
put (_all_)(=) ;
datalines;
1 1 1
2 2
3 333 3
4444 4 4
;[/pre]* and here is a log of the step extended to demo the tranwrd() effect on _infile_;[pre]857 data demo ;
858 infile datalines dsd delimiter=' ' truncover;
859 input @ ;
860 put _infile_ $char20. +1 'before the fix' ;
861 _infile_= tranwrd( _infile_,' ',' ' );
862 put _infile_ $char20. +1 'after' ;
863 input a b c d;
864 put (_all_)(=) ;
865 datalines;

1 1 1 before the fix
1 1 1 after
a=. b=1 c=1 d=1
2 2 before the fix
2 2 after
a=2 b=. c=. d=2
3 333 3 before the fix
3 333 3 after
a=3 b=333 c=. d=3
4444 4 4 before the fix
4444 4 4 after
a=4444 b=4 c=4 d=.
NOTE: The data set WORK.DEMO has 4 observations and 4 variables.
NOTE: DATA statement
[/pre]
peterC
littlestone
Fluorite | Level 6
Thank you all for help.
I apologize for not replying soon enough. I will try all your suggestions and get back to you.
Again, thank you very much.
littlestone
Fluorite | Level 6
i tried all codes and Mr. Peter.C's code worked best for me.

Again thank you all for help. I really learned a lot.
Ksharp
Super User
Hi.Actuall, Patrick and art297 's code is also right.
If they put [ pre ] before their code and [ /pre ] after their code,that would not trim the blanks in code.

Ksharp

Message was edited by: Ksharp

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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