BookmarkSubscribeRSS Feed
Sabharish
Fluorite | Level 6

hi,

 

I have a dataset variable having length 600 like below.

 

                                                                                                  variable


    An essay is generally a piece of writing that gives the authors own argument but the definition is vague overlapping with those of an article a pamphlet and a short story Essays have traditionally been subclassified as formal and informal Formal essays are characterized by serious purpose dignity logical organization length whereas the informal essay is characterized by the personal element selfrevelation individual tastes and experiences confidential manner humor graceful style rambling structure unconventionality or novelty of theme etc Essays can consist of a number of elements including literary criticism political manifestos learned arguments observations of daily life recollections and reflections of the author Almost all modern essays are written in prose but works in verse have been dubbed essays Alexander Popes An Essay on Criticism and An Essay on Man While brevity usually defines an essay voluminous works like John Lockes An Essay Concerning Human Understanding and Thomas Malthuss An Essay on the Principle of Population are counter examples In some countries the United States and Canada essays have become a formal.

 

I need to split the variable values with length 300.

like,

 

              variable1                                                                                                                       variable 2                                       

 

   An essay is generally a piece of writing that gives the authors              confidential manner humor graceful style rambling structure

own argument but the definition is vague overlapping with those       unconventionality or novelty of theme etc Essays can consist of
of an article a pamphlet and a short story Essays have traditionally          a number of elements including literary criticism political
been subclassified as formal and informal Formal essays are                 dubbed essays Alexander Popes An Essay on Criticism
characterized by serious purpose dignity logical organization               like John Lockes An Essay Concerning Human Understanding
length whereas the informal essay is characterized by the personal    Thomas Malthuss An Essay on the Principle of Population are
element selfrevelation individual tastes and experiences                      the United States and Canada essays have become a formal.  

5 REPLIES 5
Reeza
Super User

I don't see how you're separating the string but assuming it's just 300

 

var1 = SUBSTR (string, 1, 300);

var2 = SUBSTR (string, 300);

gamotte
Rhodochrosite | Level 12

If you want to avoid cutting inside of a word, you can proceed as follows :

 

data have;
format text $600.;
text="An essay is generally a piece of writing that gives the authors own argument but the definition is vague overlapping with those of an article a pamphlet and a short story Essays have traditionally been subclassified as formal and informal Formal essays are characterized by serious purpose dignity logical organization length whereas the informal essay is characterized by the personal element selfrevelation individual tastes and experiences confidential manner humor graceful style rambling structure unconventionality or novelty of theme etc Essays can consist of a number of elements including literary criticism political manifestos learned arguments observations of daily life recollections and reflections of the author Almost all modern essays are written in prose but works in verse have been dubbed essays Alexander Popes An Essay on Criticism and An Essay on Man While brevity usually defines an essay voluminous works like John Lockes An Essay Concerning Human Understanding and Thomas Malthuss An Essay on the Principle of Population are counter examples In some countries the United States and Canada essays have become a formal.";
run;

data want (keep=text1 text2);
set have;
format text1 text2 $300.;
text1=prxchange("s/^([\w ]{1,300}) .*$/$1/",-1,text);
text2=substr(text,length(text1)+1);
run;

 

 

Ksharp
Super User

There are more than 600.

Sorry. found a problem.

 

 

options noquotelenmax;
data x;
a='
An essay is generally a piece of writing that gives the authors
 own argument but the definition is vague overlapping with those of
  an article a pamphlet and a short story Essays have traditionally 
  been subclassified as formal and informal Formal essays are characterized
   by serious purpose dignity logical organization length whereas the informal 
   essay is characterized by the personal element selfrevelation individual tastes
    and experiences confidential manner humor graceful style rambling structure
     unconventionality or novelty of theme etc Essays can consist of a number 
     of elements including literary criticism political manifestos learned 
     arguments observations of daily life recollections and reflections of 
     the author Almost all modern essays are written in prose but works in 
     verse have been dubbed essays Alexander Popes An Essay on Criticism and
      An Essay on Man While brevity usually defines an essay voluminous works 
      like John Lockes An Essay Concerning Human Understanding and Thomas 
      Malthuss An Essay on the Principle of Population are counter examples 
      In some countries the United States and Canada essays have become a formal.';
run;
data temp;
 set x;
 n+1;
 length temp $ 100;
 do i=1 to countw(a,' ');
  temp=scan(a,i,' ');
  output;
 end;
keep n temp;
run;
data temp;
 set temp;
 by n;
 if first.n then do;len=0;group=0;end;
 len+length(temp)+1;
 if len gt 300 then do;len=length(temp)+1;group+1;end;
run;
data temp1;
length var $ 400;
do until(last.group);
 set temp;
 by n group;
 var=catx(' ',var,temp);
end;
keep n var;
run;
proc transpose data=temp1 out=want(drop=_name_);
by n;
var var;
run;
 
Kurt_Bremser
Super User

To cut off at the last blank before the 300th character, do

data test;
variable = 'An essay is generally a piece of writing that gives the authors own argument but the definition is vague overlapping with those of an article a pamphlet and a short story Essays have traditionally been subclassified as formal and informal Formal essays are characterized by serious purpose dignity logical organization length whereas the informal essay is characterized by the personal element selfrevelation individual tastes and experiences confidential manner humor graceful style rambling structure unconventionality or novelty of theme etc Essays can consist of a number of elements including literary criticism political manifestos learned arguments observations of daily life recollections and reflections of the author Almost all modern essays are written in prose but works in verse have been dubbed essays Alexander Popes An Essay on Criticism and An Essay on Man While brevity usually defines an essay voluminous works like John Lockes An Essay Concerning Human Understanding and Thomas Malthuss An Essay on the Principle of Population are counter examples In some countries the United States and Canada essays have become a formal.';
length variable1 variable2 $300;
i = 300;
do until (substr(variable,i,1) = ' ');
  i = i - 1;
end;
variable1 = substr(variable,1,i-1);
variable2 = substr(variable,i+1);
drop i;
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 1509 views
  • 1 like
  • 5 in conversation