DATA Step, Macro, Functions and more

length of a variable is 100 I need to cut every variable with 20 length?

Reply
Frequent Contributor
Posts: 86

length of a variable is 100 I need to cut every variable with 20 length?

Example: I'm having a variable with this value I need to split every variable with 20 length for suppose no variable value split with like "bother" ------both in one variable and ther into other variable ("But I don't see why you need to bother won't the consumer of your XPORT file just glue the cut up text back together in one variable. You could even supply the program.") Required Output: every vairble with 20 length no split words col1 -----But I don't see why you need to bother col2------won't the consumer of your XPORT col3---------file just glue the cut up text back together in col4-----one variable. You could even supply the program.")
Super User
Posts: 23,266

Re: length of a variable is 100 I need to cut every variable with 20 length?

Posted in reply to rajeshalwayswel
Post sample data and what you’ve tried so far.  Your question is ambiguous. I’m not sure if that’s due to the forum being messed up, English or not taking the time to properly phrase and illustrate your issue.  FYI - there are solutions to this problem on this site and lexjansen.com
Super User
Super User
Posts: 9,415

Re: length of a variable is 100 I need to cut every variable with 20 length?

Posted in reply to rajeshalwayswel

Your post makes no sense.  Supply, per the guidance found when you post a question, test data in the form of a datastep, what the output should look like, any logic which may happen.  Also post any code you have tried as this is not a contract work forum but a Q&A.

 

Do also note that yesterday there was an issue with the forum, you should now be able to use RichText box with code windows - {i} above post area - and proper formatting to show clearly what you want.

Frequent Contributor
Posts: 86

Re: length of a variable is 100 I need to cut every variable with 20 length?

sorry for everything if make any make inconvenience to other...
PROC Star
Posts: 2,316

Re: length of a variable is 100 I need to cut every variable with 20 length?

Posted in reply to rajeshalwayswel

You really really need to format your questions better. A big lump of text is just lazy.

From what I understood:

data HAVE;
  length VAR $100 ;
  array COL [6]  $20;
  VAR='But I don''t see why you need to bother won''t the consumer of your XPORT file just glue the cut up ';
  START=1;
  do C=1 to 6;
    END=find(VAR,' ',-START-20);
    COL[C]=substr(VAR, START, END);
    START=END;
  end; 
run; 
COL1 COL2 COL3 COL4 COL5 COL6
But I don't see why you need to bother won't the consumer of your XPORT file just glue the cut u up

 

I let you sort out the behaviour when reaching the end of the string if  the above is too basic. 

Frequent Contributor
Posts: 86

Re: length of a variable is 100 I need to cut every variable with 20 length?

Thanks...One more thing is in col5 we don't split word we need full word that needs to come in column and while running in 9.4 we have some notes.... I'll explain clear in next time of my questions...
Ask a Question
Discussion stats
  • 5 replies
  • 138 views
  • 0 likes
  • 4 in conversation