<?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 conditionally insert a row in long form data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-insert-a-row-in-long-form-data/m-p/504785#M135140</link>
    <description>This worked perfectly - thanks so much.&lt;BR /&gt;Also, I'm curious about your previous code:&lt;BR /&gt;input ID UNCLEANVARIABLE2 $25. @1 @@;&lt;BR /&gt;&lt;BR /&gt;What is the purpose of the "@1" and "@@" here? I tried to read up the definitions, but they didnt really make sense.&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
    <pubDate>Tue, 16 Oct 2018 17:17:02 GMT</pubDate>
    <dc:creator>UniversitySas</dc:creator>
    <dc:date>2018-10-16T17:17:02Z</dc:date>
    <item>
      <title>How to conditionally insert a row in long form data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-insert-a-row-in-long-form-data/m-p/499309#M132844</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Say I have the following dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data example1;&lt;BR /&gt;INFILE DATALINES ;&lt;BR /&gt; input ID UncleanVariable $25. ;&lt;BR /&gt; DATALINES;&lt;BR /&gt;1 Cyclone Limited &lt;BR /&gt;1 123 Center Street&lt;BR /&gt;1 Orlando &lt;BR /&gt;1 FL &lt;BR /&gt;1 12245&lt;BR /&gt;1 None &lt;BR /&gt;1 101(a) &lt;BR /&gt;1 Fund equipment &lt;BR /&gt;1 10000 &lt;BR /&gt;1 Lagoon Corp &lt;BR /&gt;1 3814 Wakefield Ave &lt;BR /&gt;1 Oakland &lt;BR /&gt;1 CA &lt;BR /&gt;1 19406&lt;BR /&gt;1 KL21 &lt;BR /&gt;1 Subsidise staff &lt;BR /&gt;1 200 &lt;BR /&gt;2 Imagine Sports &lt;BR /&gt;2 4556 Sun Valley &lt;BR /&gt;2 Road &lt;BR /&gt;2 Raleigh &lt;BR /&gt;2 NC &lt;BR /&gt;2 21020 &lt;BR /&gt;2 None &lt;BR /&gt;2 Airfares&lt;BR /&gt;2 14000 &lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here, there are a few errors per ID.&lt;BR /&gt;Each row should technically be defined as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;Row 1 =&amp;nbsp;Grantor&lt;/P&gt;&lt;P&gt;Row 2 = Street&lt;/P&gt;&lt;P&gt;Row 3 = City&lt;/P&gt;&lt;P&gt;Row 4 = State&lt;/P&gt;&lt;P&gt;Row 5 = Postcode&lt;/P&gt;&lt;P&gt;Row 6 = Relationship&lt;/P&gt;&lt;P&gt;Row 7 = Status&lt;/P&gt;&lt;P&gt;Row 8 = Purpose&lt;/P&gt;&lt;P&gt;Row 9 = Contribution Amount&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;The output I am looking for is:&lt;/P&gt;&lt;PRE&gt;data solution1;&lt;BR /&gt;INFILE DATALINES dsd;&lt;BR /&gt; input ID CleanedVariable ~ $30. Category $25. ;&lt;BR /&gt; DATALINES;&lt;BR /&gt;1,Cyclone Limited,Grantor&lt;BR /&gt;1,123 Center Street,Street&lt;BR /&gt;1,Orlando,City&lt;BR /&gt;1,FL,State&lt;BR /&gt;1,12245,Postcode&lt;BR /&gt;1,Parent company,Relationship&lt;BR /&gt;1,101(a),Status&lt;BR /&gt;1,Fund equipment,Purpose &lt;BR /&gt;1,10000, Contribution Amount&lt;BR /&gt;1,Lagoon Corp,Grantor &lt;BR /&gt;1,3814 Wakefield Ave,Street &lt;BR /&gt;1,Oakland,City&lt;BR /&gt;1,CA,State &lt;BR /&gt;1,19406,Postcode&lt;BR /&gt;1,N/A,Relationship&lt;BR /&gt;1,KL21,Status&lt;BR /&gt;1,Subsidise staff,Purpose&lt;BR /&gt;1,200,Contribution Amount&lt;BR /&gt;2,Imagine Sports,Grantor&lt;BR /&gt;2,4556 Sun Valley Road,Street&lt;BR /&gt;2,Raleigh,City&lt;BR /&gt;2,NC,State&lt;BR /&gt;2,21020,Postcode&lt;BR /&gt;2,Subsidiary,Relationship&lt;BR /&gt;2,Missing,Status&lt;BR /&gt;2,Airfares,Purpose&lt;BR /&gt;2,14000,Contribution Amount&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/PRE&gt;&lt;P&gt;There are a few problems I want to address. I'm not sure if there is a one-size fits all solution, so that is okay if there isn't. Let me first visualise the problem, with a few screenshots.&lt;/P&gt;&lt;P&gt;This is the&amp;nbsp;&lt;STRONG&gt;original data:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sasforums_help.jpg" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/23587iECACD3556DD8D391/image-size/large?v=v2&amp;amp;px=999" role="button" title="sasforums_help.jpg" alt="sasforums_help.jpg" /&gt;&lt;/span&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error 1 - The value for "relationship" is missing in the input data, so the "status" row is read prematurely. Is there a way to adjust this so that every Sixth row is either "none" or "None", and if not, insert the value "N/A" between row 5 and 6 in the original set? My criteria is that the value should ALWAYS be "none" or "None" and if not, "N/A" is input.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error 2 - Here the address row has spilled over to the city row. Except for manually correcting this, is there a way to fix this spillover in a big data set? The pattern I've seen is that usually it's words like "floor" that spill over from the address. Or if there are more than two spaces in the address line, it will spillover. So we have 4556[1 space]Sun[2nd space]Valley[&lt;STRONG&gt;3rd space&lt;/STRONG&gt;] Road.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error 3 - arises because of error 2.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error 4 - Assuming errors 1-3 are all addressed, there is a new error, very similar to error 1. Here the value for "Status" is missing, and should be replaced as "N/A" or "Missing" to indicate there was no value for this. The only criteria I can think of is that there should never any spaces contained in the value of this row, but it can contain brackets () and alphanumeric values.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Ideally, my cleaned data should look like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sashelp2.jpg" style="width: 527px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/23588iDEEFADA6CAA04684/image-size/large?v=v2&amp;amp;px=999" role="button" title="sashelp2.jpg" alt="sashelp2.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So Ideally, I would like to correct all the Errors, but in terms of importance;&lt;/P&gt;&lt;P&gt;Errors 1, 4, 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for any help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: In the last screenshot, "solution1" it should read "Street" not "Street Address" - my mistake.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2018 22:48:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-insert-a-row-in-long-form-data/m-p/499309#M132844</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2018-09-26T22:48:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to conditionally insert a row in long form data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-insert-a-row-in-long-form-data/m-p/499313#M132846</link>
      <description>&lt;P&gt;First comment: GIGO&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have a "row" that might have a limited number of responses, such as possibly relationship you might be able to test the value and if not in the list advance the "category" value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How many records (IDs in this case)&amp;nbsp;do you have to process? If the number is smallish, say under 100 or so, it may be quicker to edit the file manually by inserting appropriate lines then to try to work out "logic" for something like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Generally if someone brings something this poor the estimate on hours and $$ goes way up.&lt;/P&gt;
&lt;P&gt;And I suggest to them to get a data storage system designed more recently than a shoe box filled with 3x5 cards.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2018 22:57:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-insert-a-row-in-long-form-data/m-p/499313#M132846</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-09-26T22:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to conditionally insert a row in long form data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-insert-a-row-in-long-form-data/m-p/499325#M132848</link>
      <description>&lt;P&gt;Agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;Fixing garbage data is expensive and the result is never guaranteed.&lt;/P&gt;
&lt;P&gt;If you are stuck with it, this will get you started:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data EXAMPLE1;
  input ID UNCLEANVARIABLE $25. ;
  CATEGORY_NO+1;
  if CATEGORY_NO=10 then CATEGORY_NO=1; 
  select(CATEGORY_NO);

    %* Grantor ;      
    when(1 ) ;     
 
    %* Street  ;
    when(2 ) if countw(UNCLEANVARIABLE)=3 then do;
      input ID UNCLEANVARIABLE2 $25. @1 @@;
      if UNCLEANVARIABLE2 in('Floor','Road') then do;
        CLEANVARIABLE=catx(' ',UNCLEANVARIABLE,UNCLEANVARIABLE2);
        input;
      end;
    end;

    %* City     ;
    when(3 ) ;

    %* State    ;
    when(4 ) ;

    %* Postcode ;
    when(5 ) ;

    %* Relationship;
    when(6 ) if upcase(UNCLEANVARIABLE) ne 'NONE' then do;
      CLEANVARIABLE='N/A';
      output;
      CATEGORY_NO+1;
      CLEANVARIABLE=UNCLEANVARIABLE;
    end;

    otherwise;
  end;
  CLEANVARIABLE=coalescec(CLEANVARIABLE,UNCLEANVARIABLE);
  output;
cards;
1 Cyclone Limited 
1 123 Center Street
1 Orlando 
1 FL 
1 12245
1 None 
1 101(a) 
1 Fund equipment 
1 10000 
1 Lagoon Corp 
1 3814 Wakefield Ave 
1 Oakland 
1 CA 
1 19406
1 KL21 
1 Subsidise staff 
1 200 
2 Imagine Sports 
2 4556 Sun Valley 
2 Road 
2 Raleigh 
2 NC 
2 21020 
2 None 
2 Airfares
2 14000 
run;
&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.EXAMPLE1" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;ID&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;CATEGORY_NO&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;CLEANVARIABLE&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;Cyclone Limited&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="l data"&gt;123 Center Street&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="l data"&gt;Orlando&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;TD class="l data"&gt;FL&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;5&lt;/TD&gt;
&lt;TD class="l data"&gt;12245&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;6&lt;/TD&gt;
&lt;TD class="l data"&gt;None&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;7&lt;/TD&gt;
&lt;TD class="l data"&gt;101(a)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;8&lt;/TD&gt;
&lt;TD class="l data"&gt;Fund equipment&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;9&lt;/TD&gt;
&lt;TD class="l data"&gt;10000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;Lagoon Corp&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="l data"&gt;3814 Wakefield Ave&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="l data"&gt;Oakland&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;TD class="l data"&gt;CA&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;5&lt;/TD&gt;
&lt;TD class="l data"&gt;19406&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="r data"&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;6&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="l data"&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;N/A&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;7&lt;/TD&gt;
&lt;TD class="l data"&gt;KL21&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;8&lt;/TD&gt;
&lt;TD class="l data"&gt;Subsidise staff&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;9&lt;/TD&gt;
&lt;TD class="l data"&gt;200&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;Imagine Sports&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="r data"&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="l data"&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;4556 Sun Valley Road&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="l data"&gt;Raleigh&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;TD class="l data"&gt;NC&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;5&lt;/TD&gt;
&lt;TD class="l data"&gt;21020&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;6&lt;/TD&gt;
&lt;TD class="l data"&gt;None&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;7&lt;/TD&gt;
&lt;TD class="l data"&gt;Airfares&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;8&lt;/TD&gt;
&lt;TD class="l data"&gt;14000&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2018 23:57:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-insert-a-row-in-long-form-data/m-p/499325#M132848</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-09-26T23:57:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to conditionally insert a row in long form data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-insert-a-row-in-long-form-data/m-p/499681#M132996</link>
      <description>&lt;P&gt;Hi Chris, thanks so much for your response.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Unfortunately I am indeed stuck with the data, and have accepted that a lot of manual scrubbing is going to be needed. Although, I am still pretty new to SAS and coding, so I really appreciate your response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could I just clarify how I would amend the code you've written so that I wouldn't need to input the raw data myself, and could just use an already imported data set?&lt;/P&gt;&lt;P&gt;In addition,&amp;nbsp;I would like to have labelled rows, like the following:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IF x=1 THEN Var_Name="Grantor";
	ELSE IF x=2 THEN Var_Name= "Street";
	ELSE IF x=3 THEN Var_Name = "City";
	ELSE IF x=4 THEN Var_Name= "State";
	ELSE IF x=5 THEN Var_Name = "Postcode";
	ELSE IF x=6 THEN Var_Name= "Relationship";
	ELSE IF x=7 THEN Var_Name = "Status";
	ELSE IF x=8 THEN Var_Name= "Purpose";
	ELSE IF x=0 THEN Var_Name= "Contribution";&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So that I can then transpose this data into a wide form.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 19:38:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-insert-a-row-in-long-form-data/m-p/499681#M132996</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2018-09-27T19:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to conditionally insert a row in long form data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-insert-a-row-in-long-form-data/m-p/499683#M132997</link>
      <description>&lt;P&gt;In total I have 21 IDs to process, and of the 21, around 16 have constant errors in them.&lt;/P&gt;&lt;P&gt;In terms of total observations, there are over 4 million.&lt;BR /&gt;&lt;BR /&gt;The majority of the errors are the missing "&lt;STRONG&gt;relationship&lt;/STRONG&gt;", I'd say about 80% of them. The remaining 20% of the errors are 19% missing &lt;STRONG&gt;"status"&lt;/STRONG&gt;, and the final 1% of errors are the miscellaneous spillovers such as "Floor" or "Street" being read into the&amp;nbsp;&lt;STRONG&gt;"city"&lt;/STRONG&gt;..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That's still 40,000 records to deal with, but I'm sure once the initial errors are dealt with, it'll be easier to identify some sort of pattern to deal with it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 19:53:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-insert-a-row-in-long-form-data/m-p/499683#M132997</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2018-09-27T19:53:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to conditionally insert a row in long form data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-insert-a-row-in-long-form-data/m-p/499727#M133013</link>
      <description>&lt;P&gt;&lt;EM&gt;1. just use an already imported data set?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Replace the INPUT statement with a SET statement&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;2. Have labelled rows&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Use variable CATEGORY_NO. Your code is fine. Or use my select sections,&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 22:39:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-insert-a-row-in-long-form-data/m-p/499727#M133013</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-09-27T22:39:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to conditionally insert a row in long form data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-insert-a-row-in-long-form-data/m-p/500119#M133140</link>
      <description>&lt;P&gt;Thanks for that, I seem to be getting an error though. Would you mind telling me what I'm doing wrong?&lt;/P&gt;&lt;P&gt;I've used this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data EXAMPLE1;
  SET test_code;
   CATEGORY_NO+1;
  if CATEGORY_NO=10 then CATEGORY_NO=1; 
  select(CATEGORY_NO);

    %* Grantor ;      
    when(1 ) ;     
 
    %* Street  ;
    when(2 ) if countw(UNCLEANVARIABLE)=3 then do;
      input ID UNCLEANVARIABLE2 $25. @1 @@;
      if UNCLEANVARIABLE2 in('Floor','Road') then do;
        CLEANVARIABLE=catx(' ',UNCLEANVARIABLE,UNCLEANVARIABLE2);
        input;
      end;
    end;

    %* City     ;
    when(3 ) ;

    %* State    ;
    when(4 ) ;

    %* Postcode ;
    when(5 ) ;

    %* Relationship;
    when(6 ) if upcase(UNCLEANVARIABLE) ne 'NONE' then do;
      CLEANVARIABLE='N/A';
      output;
      CATEGORY_NO+1;
      CLEANVARIABLE=UNCLEANVARIABLE;
    end;

    otherwise;
  end;
  CLEANVARIABLE=coalescec(CLEANVARIABLE,UNCLEANVARIABLE);
  output;

RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Where SET test_code is just the full data set of the sample I posted here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The error I am getting is:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;ERROR: No DATALINES or INFILE statement.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, how come in your code you have the variables grantor, street, city etc... but they do not appear in the final output in a separate column?&lt;BR /&gt;If I wanted to add the additional:&amp;nbsp;&lt;STRONG&gt;Status, Purpose, &lt;/STRONG&gt;and&lt;STRONG&gt; Contribution,&amp;nbsp;&lt;/STRONG&gt;would that just be by appending the above code with:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  %* Status;
    when(7 ) ;

    %* Relationship ;
    when(8 ) ;

    %* Contribution;
    when(9 ) ;&lt;BR /&gt;&lt;BR /&gt; CLEANVARIABLE=coalescec(CLEANVARIABLE,Var);&lt;BR /&gt; output;&lt;BR /&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Sep 2018 20:08:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-insert-a-row-in-long-form-data/m-p/500119#M133140</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2018-09-29T20:08:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to conditionally insert a row in long form data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-insert-a-row-in-long-form-data/m-p/500221#M133183</link>
      <description>&lt;P&gt;Apologies, just replacing &lt;FONT face="courier new,courier"&gt;infile&lt;/FONT&gt;&amp;nbsp;with &lt;FONT face="courier new,courier"&gt;set&lt;/FONT&gt; was not quite sufficient.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Provided your data is not huge, &lt;FONT face="courier new,courier"&gt;set point=&amp;nbsp;&lt;/FONT&gt;is the easiest replacement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data HAVE;
  input ID UNCLEANVARIABLE $25. ;
cards;
1 Cyclone Limited 
1 123 Center Street
1 Orlando 
1 FL 
1 12245
1 None 
1 101(a) 
1 Fund equipment 
1 10000 
1 Lagoon Corp 
1 3814 Wakefield Ave 
1 Oakland 
1 CA 
1 19406
1 KL21 
1 Subsidise staff 
1 200 
2 Imagine Sports 
2 4556 Sun Valley 
2 Road 
2 Raleigh 
2 NC 
2 21020 
2 None 
2 Airfares
2 14000 
run;
data WANT;
  OBS_NO+1;
  set HAVE point=OBS_NO nobs=NOBS;
  CATEGORY_NO+1;
  if CATEGORY_NO=10 then CATEGORY_NO=1; 
  select(CATEGORY_NO);
 
    %* Street  ;
    when(2 ) if countw(UNCLEANVARIABLE)=3 then do;
      %* see whats next;
      TMP=OBS_NO+1;
      set HAVE(rename=(UNCLEANVARIABLE=UNCLEANVARIABLE2)) point=TMP;
      if UNCLEANVARIABLE2 in('Floor','Road') then do;
        CLEANVARIABLE=catx(' ',UNCLEANVARIABLE,UNCLEANVARIABLE2);
        OBS_NO+1;
      end;
    end;

    %* Relationship;
    when(6 ) if upcase(UNCLEANVARIABLE) ne 'NONE' then do;
      CLEANVARIABLE='N/A';
      output;
      CATEGORY_NO+1;
      CLEANVARIABLE=UNCLEANVARIABLE;
    end;

    otherwise;
  end;
  CLEANVARIABLE=coalescec(CLEANVARIABLE,UNCLEANVARIABLE);
  output;
  if OBS_NO=NOBS then stop;
  keep ID CATEGORY_NO CLEANVARIABLE;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Also, how come in your code you have the variables grantor, street, city etc... but they do not appear in the final output in a separate column?&lt;/EM&gt;&lt;BR /&gt;I don't have these variables anywhere. I just created space holders as a model, for you to fill. What you propose for&amp;nbsp;Relationship looks fine. Please do understand the code provided.&lt;/P&gt;
&lt;P&gt;The people helping you here are not here do do your work for you and give you a fish, they are here to teach you how to fish.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 30 Sep 2018 21:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-insert-a-row-in-long-form-data/m-p/500221#M133183</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-09-30T21:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to conditionally insert a row in long form data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-insert-a-row-in-long-form-data/m-p/504785#M135140</link>
      <description>This worked perfectly - thanks so much.&lt;BR /&gt;Also, I'm curious about your previous code:&lt;BR /&gt;input ID UNCLEANVARIABLE2 $25. @1 @@;&lt;BR /&gt;&lt;BR /&gt;What is the purpose of the "@1" and "@@" here? I tried to read up the definitions, but they didnt really make sense.&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Tue, 16 Oct 2018 17:17:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-insert-a-row-in-long-form-data/m-p/504785#M135140</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2018-10-16T17:17:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to conditionally insert a row in long form data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-insert-a-row-in-long-form-data/m-p/504915#M135184</link>
      <description>&lt;P&gt;@1 repositions the pointer at the start of the line so the next input statement will read from the start.&lt;/P&gt;
&lt;P&gt;@@&amp;nbsp; keeps the current record open so the&amp;nbsp;&lt;SPAN&gt;next input statement will read the&amp;nbsp;same record again.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;One&amp;nbsp;@ keeps the record&amp;nbsp;open just for the duration&amp;nbsp;of the current implicit data step loop iteration (until the&amp;nbsp;interpreter&amp;nbsp;reaches &lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Two&amp;nbsp;@s keep the record&amp;nbsp;open across data step implicit iterations.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 21:36:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-insert-a-row-in-long-form-data/m-p/504915#M135184</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-10-16T21:36:55Z</dc:date>
    </item>
  </channel>
</rss>

