<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to bring four observations into four different columns from a text file in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-bring-four-observations-into-four-different-columns-from/m-p/951674#M45581</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have imported my log file into a sas dataset with only one variable, the variable text.&lt;/P&gt;
&lt;P&gt;Then I did some cleanup into it in order to keep only the four observations sequence as below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1         + %doit(/dwh_actuariat/sasdata/Data_Retention,2011,wu,prop,habi,fev,4V3098387)
the sas dataset wu_prop_prmfev2011 exist
this is an prop premium dataset
0 observations where found for the agreement number: 4V3098387 into the dataset wu_prop_prmfev2011
2         + %doit(/dwh_actuariat/sasdata/Data_Retention,2011,wu,prop,habi,fev,P34V3098387)
the sas dataset wu_prop_prmfev2011 exist
this is an prop premium dataset
1 observations where found for the agreement number: P34V3098387 into the dataset wu_prop_prmfev2011&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so for the first observation I have something starting with + %doit&lt;/P&gt;
&lt;P&gt;second observation&amp;nbsp; something starting with the sas dataset&lt;/P&gt;
&lt;P&gt;third observation this is an&lt;/P&gt;
&lt;P&gt;and last observation x observations where found...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this 4 observations sequence is repeted 311 times.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create a dataset having 311 observations / lines with var1=first line var2=second line var3=thrid line and finally var4 = fourth line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In summary, we start with a sas dataset having 1 variable = text with 1244 observations and I want to transform this information into a new dataset of 311 lines and 4 variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do we do that&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 22 Nov 2024 20:19:58 GMT</pubDate>
    <dc:creator>alepage</dc:creator>
    <dc:date>2024-11-22T20:19:58Z</dc:date>
    <item>
      <title>How to bring four observations into four different columns from a text file</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-bring-four-observations-into-four-different-columns-from/m-p/951653#M45575</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have cleanup my log file to get something like that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1         + %doit(/dwh_actuariat/sasdata/Data_Retention,2011,wu,prop,habi,fev,4V3098387)
the sas dataset wu_prop_prmfev2011 exist
this is an prop premium dataset
0 observations where found for the agreement number: 4V3098387 into the dataset wu_prop_prmfev2011
2         + %doit(/dwh_actuariat/sasdata/Data_Retention,2011,wu,prop,habi,fev,P34V3098387)
the sas dataset wu_prop_prmfev2011 exist
this is an prop premium dataset
1 observations where found for the agreement number: P34V3098387 into the dataset wu_prop_prmfev2011&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so If we look at the above-mentioned example, it is the content of the variable text.&amp;nbsp; What I would like to get is a dataset with two lines and four columns where in the first column we have the %doit statement, second column we have the sas dataset ... exits, third column this is a prop premium datasets and last column remarks =&amp;nbsp;&lt;CODE class=" language-sas"&gt;1 observations where found for the agreement number: P34V3098387 into the dataset wu_prop_prmfev2011&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How to do those manipulation ?&lt;/P&gt;</description>
      <pubDate>Fri, 22 Nov 2024 17:05:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-bring-four-observations-into-four-different-columns-from/m-p/951653#M45575</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2024-11-22T17:05:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to bring four observations into four different columns from a text file</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-bring-four-observations-into-four-different-columns-from/m-p/951659#M45576</link>
      <description>&lt;P&gt;Use four INPUT statements:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
infile "...." truncover;
length var1 var2 var3 var4 $80;
input var1 $80.;
input var2 $80.;
input var3 $80.;
input var4 $80.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Increase/decrease the lengths and informats as needed;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Nov 2024 17:48:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-bring-four-observations-into-four-different-columns-from/m-p/951659#M45576</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-11-22T17:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to bring four observations into four different columns from a text file</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-bring-four-observations-into-four-different-columns-from/m-p/951662#M45577</link>
      <description>&lt;P&gt;What "manipulation"?&amp;nbsp; Just read it that way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First let's create a file with the lines of text you posted so we have something we can program against.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename text temp;
options parmcards=text;
parmcards4;
1         + %doit(/dwh_actuariat/sasdata/Data_Retention,2011,wu,prop,habi,fev,4V3098387)
the sas dataset wu_prop_prmfev2011 exist
this is an prop premium dataset
0 observations where found for the agreement number: 4V3098387 into the dataset wu_prop_prmfev2011
2         + %doit(/dwh_actuariat/sasdata/Data_Retention,2011,wu,prop,habi,fev,P34V3098387)
the sas dataset wu_prop_prmfev2011 exist
this is an prop premium dataset
1 observations where found for the agreement number: P34V3098387 into the dataset wu_prop_prmfev2011
;;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you know the file consists of 4 lines per observation you could use the N= option of the INFILE statement and the # cursor motion operator of the INPUT statement.&amp;nbsp; So perhaps something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile text n=4 truncover ;
  input #1 @'+' doit_call $100.
        #2 @'dataset' memname :$32. status :$8. 
        #3 comment $100.
        #4 nobs @'agreement number:' agreement :$20.
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1732298271779.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102467iD8DF888FE2765D76/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1732298271779.png" alt="Tom_0-1732298271779.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Nov 2024 17:58:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-bring-four-observations-into-four-different-columns-from/m-p/951662#M45577</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-22T17:58:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to bring four observations into four different columns from a text file</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-bring-four-observations-into-four-different-columns-from/m-p/951671#M45579</link>
      <description>How do we do that if I have already the variable text into a SAS dataset and if I have done some cleanup to make sure that we have a structure of 4 lines</description>
      <pubDate>Fri, 22 Nov 2024 19:22:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-bring-four-observations-into-four-different-columns-from/m-p/951671#M45579</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2024-11-22T19:22:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to bring four observations into four different columns from a text file</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-bring-four-observations-into-four-different-columns-from/m-p/951673#M45580</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76331"&gt;@alepage&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;How do we do that if I have already the variable text into a SAS dataset and if I have done some cleanup to make sure that we have a structure of 4 lines&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Depends what the dataset you have looks like.&amp;nbsp; Share what you have in the data for a couple of observations. For example if you have a dataset named HAVE with four variables named LINE1 to LINE4 you could share example of what you have for one observations by creating a program like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  length line1-line4 $100;
  line1=' + %xxx();';
  line2='other stuff';
  line3='third line stuff';
  line4='last line stuff';
  output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have those strings in four variables then you can use SCAN() to pull out words from the strings.&amp;nbsp; You can use INPUT() function to convert strings that look like numbers into actual numbers.&amp;nbsp; If you need to search the text for the location to pull out you can probably use FIND() or one of the PX... functions that supports the use for regular expressions.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Nov 2024 20:07:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-bring-four-observations-into-four-different-columns-from/m-p/951673#M45580</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-22T20:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to bring four observations into four different columns from a text file</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-bring-four-observations-into-four-different-columns-from/m-p/951674#M45581</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have imported my log file into a sas dataset with only one variable, the variable text.&lt;/P&gt;
&lt;P&gt;Then I did some cleanup into it in order to keep only the four observations sequence as below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1         + %doit(/dwh_actuariat/sasdata/Data_Retention,2011,wu,prop,habi,fev,4V3098387)
the sas dataset wu_prop_prmfev2011 exist
this is an prop premium dataset
0 observations where found for the agreement number: 4V3098387 into the dataset wu_prop_prmfev2011
2         + %doit(/dwh_actuariat/sasdata/Data_Retention,2011,wu,prop,habi,fev,P34V3098387)
the sas dataset wu_prop_prmfev2011 exist
this is an prop premium dataset
1 observations where found for the agreement number: P34V3098387 into the dataset wu_prop_prmfev2011&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so for the first observation I have something starting with + %doit&lt;/P&gt;
&lt;P&gt;second observation&amp;nbsp; something starting with the sas dataset&lt;/P&gt;
&lt;P&gt;third observation this is an&lt;/P&gt;
&lt;P&gt;and last observation x observations where found...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this 4 observations sequence is repeted 311 times.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create a dataset having 311 observations / lines with var1=first line var2=second line var3=thrid line and finally var4 = fourth line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In summary, we start with a sas dataset having 1 variable = text with 1244 observations and I want to transform this information into a new dataset of 311 lines and 4 variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do we do that&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Nov 2024 20:19:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-bring-four-observations-into-four-different-columns-from/m-p/951674#M45581</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2024-11-22T20:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to bring four observations into four different columns from a text file</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-bring-four-observations-into-four-different-columns-from/m-p/951677#M45582</link>
      <description>&lt;P&gt;To convert every four observations into one here are a couple of methods.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could add a group variable and then transpose by that variable.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will create a dataset with 5 variables.&amp;nbsp; GROUP and TEXT1 to TEXT4.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data step1;
  set have;
  group + mod(_n_,4)=1 ;
run;
proc transpose data=step1 out=step2(drop=_name_) prefix=text;
  by group;
  var text;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could do the same thing in single data step by defining an array and putting a DO loop around the SET statement.&amp;nbsp; So in this example we also add the GROUP variable.&amp;nbsp; We also need to set the length of the new variables, which we can do when we define the array.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data step2;
   group+1;
   do i=1 to 4;
      array t $200 text1-text4;
      set have;
      t[i]=text;
   end;
  drop i text;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Let's read in your example data and try it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile text truncover;
  input text $char200.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1732309147247.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102469i2B744E646F053BD1/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1732309147247.png" alt="Tom_0-1732309147247.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Nov 2024 20:59:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-bring-four-observations-into-four-different-columns-from/m-p/951677#M45582</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-22T20:59:20Z</dc:date>
    </item>
  </channel>
</rss>

