BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
woo
Barite | Level 11 woo
Barite | Level 11

have space separated file like below. problem is when var 3 has 0 value file don't have extra space mentioned and next field continues.

 

var1/var2/var3/4/var5

 

1  "host1"  2  "file1"  "file2"   123456

4  "host1"  "host2"   "host3"   "host4"  3  "file1"  "file2"  "file3"  456789

2  "host1"  "host2"   0  9922

 

want

var1      var2                                                        var3              var4                                var5

1           "host1"                                                     2                   "file1"  "file2"                   123456

4           "host1"  "host2"   "host3"   "host4"           3                   "file1"  "file2"  "file3"        456789       

2           "host1"  "host2"                                        0                   _null_                              9922

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Looks pretty simple to me.

data want ;
  length var1 8 var2 $200 var3 8 var4 $200 var5 8;
  length i 8 next $200;
  input var1 @;
  do i=1 to var1 ;
    input next @;
    var2 = catx(' ',var2,next);
  end;
  input var3 @;
  do i=1 to var3 ;
    input next @;
    var4 = catx(' ',var4,next);
  end;
  input var5  ;
  drop i next ;
cards;
1  "host1"  2  "file1"  "file2"   123456
4  "host1"  "host2"   "host3"   "host4"  3  "file1"  "file2"  "file3"  456789
2  "host1"  "host2"   0  9922
;

View solution in original post

3 REPLIES 3
Astounding
PROC Star

Assuming that you already have a way to read in VAR1 through VAR5 for the non-zero rows, here is the change to make:

 

input var1 var2 var3 @ ;

if var3 = 0 then input var5;

else input var4 var5;

 

This is obviously missing a lot of the details of the INPUT statement.  But it's the trialing @ that you will need to add, to be able to modify your existing program.

Tom
Super User Tom
Super User

Looks pretty simple to me.

data want ;
  length var1 8 var2 $200 var3 8 var4 $200 var5 8;
  length i 8 next $200;
  input var1 @;
  do i=1 to var1 ;
    input next @;
    var2 = catx(' ',var2,next);
  end;
  input var3 @;
  do i=1 to var3 ;
    input next @;
    var4 = catx(' ',var4,next);
  end;
  input var5  ;
  drop i next ;
cards;
1  "host1"  2  "file1"  "file2"   123456
4  "host1"  "host2"   "host3"   "host4"  3  "file1"  "file2"  "file3"  456789
2  "host1"  "host2"   0  9922
;
woo
Barite | Level 11 woo
Barite | Level 11

Thanks Tom. I ran your code and it looks great.

 

 

 

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 927 views
  • 5 likes
  • 3 in conversation