<?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: Use values from an existing column to fill missing values in other columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751279#M236473</link>
    <description>&lt;P&gt;In a nutshell, I am seeking the equivalent SAS code of the following Python code shown below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import re

manufacturer = '(gmc | hyundai | toyota | mitsubishi | ford | chevrolet | ram | buick | jeep | dodge | subaru | nissan | audi | rover  | lexus \
| honda | chrysler | mini | pontiac | mercedes-benz | cadillac | bmw | kia | volvo | volkswagen | jaguar | acura | saturn | mazda | \
mercury | lincoln | infiniti | ferrari | fiat | tesla | land rover | harley-davidson | datsun | alfa-romeo | morgan | aston-martin | porche \
| hennessey)'
condition = '(excellent | good | fair | like new | salvage | new)'
fuel = '(gas | hybrid | diesel |electric)'
title_status = '(clean | lien | rebuilt | salvage | missing | parts only)'
transmission = '(automatic | manual)'
drive = '(4x4 | awd | fwd | rwd | 4wd)'
size = '(mid-size | full-size | compact | sub-compact)'
type_ = '(sedan | truck | SUV | mini-van | wagon | hatchback | coupe | pickup | convertible | van | bus | offroad)'
paint_color = '(red | grey | blue | white | custom | silver | brown | black | purple | green | orange | yellow)'
cylinders = '(\s[1-9] cylinders? |\s1[0-6]? cylinders?)'

keys =    ['manufacturer', 'condition', 'fuel', 'title_status', 'transmission', 'drive','size', 'type', 'paint_color' , 'cylinders']
columns = [ manufacturer,   condition,   fuel,  title_status, transmission ,drive, size, type_, paint_color,   cylinders]

for i,column in zip(keys,columns):
    database[i] = database[i].fillna(
      database['description'].str.extract(column, flags=re.IGNORECASE, expand=False)).str.lower()

database.drop('description', axis=1, inplace= True)&lt;/PRE&gt;&lt;P&gt;I have a large dataset in SAS that has 17 variables of which four are numeric and 13 character/string. The original dataset that I am using can be found here:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://www.kaggle.com/austinreese/craigslist-carstrucks-data" rel="nofollow noreferrer" target="_blank"&gt;https://www.kaggle.com/austinreese/craigslist-carstrucks-data&lt;/A&gt;.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;cylinders&lt;/LI&gt;&lt;LI&gt;condition&lt;/LI&gt;&lt;LI&gt;drive&lt;/LI&gt;&lt;LI&gt;paint_color&lt;/LI&gt;&lt;LI&gt;type&lt;/LI&gt;&lt;LI&gt;manufacturer&lt;/LI&gt;&lt;LI&gt;title_status&lt;/LI&gt;&lt;LI&gt;model&lt;/LI&gt;&lt;LI&gt;fuel&lt;/LI&gt;&lt;LI&gt;transmission&lt;/LI&gt;&lt;LI&gt;description&lt;/LI&gt;&lt;LI&gt;region&lt;/LI&gt;&lt;LI&gt;state&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;price (num)&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;posting_date (num)&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;odometer (num)&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;year (num)&lt;/STRONG&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;After applying specific filters to the numeric columns, there are no missing values for each numeric variable. However, there are thousands to hundreds of thousands of missing variables for the remaining 14 char/string variables. H&lt;SPAN&gt;ow can I write the equivalent SAS code where I use regex on the description column to fill missing values of the other string/char columns with categorical values such as cylinders, condition, drive, paint_color, and so on?&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 30 Jun 2021 14:58:31 GMT</pubDate>
    <dc:creator>Vicente95</dc:creator>
    <dc:date>2021-06-30T14:58:31Z</dc:date>
    <item>
      <title>Use values from an existing column to fill missing values in other columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751116#M236401</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to SAS programming, and working on a personal project to analyze used cars listing on Craigslist between April and May 2021. Here is the dataset that I am using:&amp;nbsp;&lt;A href="https://www.kaggle.com/austinreese/craigslist-carstrucks-data" target="_blank" rel="noopener"&gt;https://www.kaggle.com/austinreese/craigslist-carstrucks-data&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found a similar blog post on the towards data science website (&lt;A href="https://towardsdatascience.com/end-to-end-data-science-project-predicting-used-car-prices-using-regression-1b12386c69c8" target="_blank" rel="noopener"&gt;https://towardsdatascience.com/end-to-end-data-science-project-predicting-used-car-prices-using-regression-1b12386c69c8&lt;/A&gt;) where the author, Jose Portillo, used an older dataset with the same variables. However, Jose coded his project in Python whereas I am doing mine in SAS.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import re

manufacturer = '(gmc | hyundai | toyota | mitsubishi | ford | chevrolet | ram | buick | jeep | dodge | subaru | nissan | audi | rover  | lexus \
| honda | chrysler | mini | pontiac | mercedes-benz | cadillac | bmw | kia | volvo | volkswagen | jaguar | acura | saturn | mazda | \
mercury | lincoln | infiniti | ferrari | fiat | tesla | land rover | harley-davidson | datsun | alfa-romeo | morgan | aston-martin | porche \
| hennessey)'
condition = '(excellent | good | fair | like new | salvage | new)'
fuel = '(gas | hybrid | diesel |electric)'
title_status = '(clean | lien | rebuilt | salvage | missing | parts only)'
transmission = '(automatic | manual)'
drive = '(4x4 | awd | fwd | rwd | 4wd)'
size = '(mid-size | full-size | compact | sub-compact)'
type_ = '(sedan | truck | SUV | mini-van | wagon | hatchback | coupe | pickup | convertible | van | bus | offroad)'
paint_color = '(red | grey | blue | white | custom | silver | brown | black | purple | green | orange | yellow)'
cylinders = '(\s[1-9] cylinders? |\s1[0-6]? cylinders?)'

keys =    ['manufacturer', 'condition', 'fuel', 'title_status', 'transmission', 'drive','size', 'type', 'paint_color' , 'cylinders']
columns = [ manufacturer,   condition,   fuel,  title_status, transmission ,drive, size, type_, paint_color,   cylinders]

for i,column in zip(keys,columns):
    database[i] = database[i].fillna(
      database['description'].str.extract(column, flags=re.IGNORECASE, expand=False)).str.lower()

database.drop('description', axis=1, inplace= True)&lt;/PRE&gt;&lt;P&gt;There are some minor differences such as the drive, type, and num_of_cylinders. However, almost all the variables are the same. &lt;STRONG&gt;If we hold all the variables constant, how can I write the&amp;nbsp;&lt;EM&gt;same&lt;/EM&gt; code in SAS to extract data from the&amp;nbsp;&lt;EM&gt;description&amp;nbsp;&lt;/EM&gt;column to fill in the missing values in the manufacturer, condition, fuel, transmission, and so on columns?&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think I have created the list correctly, however here is what I have done so far to format each column and its observations into a list.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let manufacturer = (gmc,hyundai,toyota,mitsubishi,ford,chevrolet,ram,buick,jeep,dodge,subaru,nissan,audi,rover,lexus,honda,chrysler,mini,pontiac,mercedes-benz,cadillac,bmw,kia,volvo,volkswagen,jaguar,acura,saturn,mazda,mercury,lincoln,infiniti,ferrari,fiat,tesla,land rover,harley-davidson,datsun,alfa-romeo,morgan,aston-martin,porche,hennessey);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let condition = (excellent,good,fair,like new,salvage,new);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let fuel = (gas,hybrid,diesel,electric);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let title_status = (clean,lien,rebuilt,salvage,missing,parts only);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let transmission = (automatic,manual);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let drive = (4wd,fwd,rwd);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let size = (mid-size,full-size,compact,sub-compact);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let type = (sedan,truck,SUV,mini-van,wagon,hatchback,coupe,pickup,convertible,van,bus,offroad);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let paint_color = (red,grey,blue,white,custom,silver,brown,black,purple,green,orange,yellow);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let cylinders = (s[1-9] cylinders?, s1[0-6]? cylinders?);&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jun 2021 15:00:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751116#M236401</guid>
      <dc:creator>Vicente95</dc:creator>
      <dc:date>2021-06-30T15:00:01Z</dc:date>
    </item>
    <item>
      <title>Re: Use values from an existing column to fill missing values in other columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751129#M236409</link>
      <description>&lt;P&gt;I am unsure what you want, but the cylinders variable contains a (corrupt) regular expression rather than a list like the other variables.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jun 2021 05:47:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751129#M236409</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-06-30T05:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: Use values from an existing column to fill missing values in other columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751131#M236411</link>
      <description>So, I want the equivalent SAS code of what is contained in the screenshot since the author wrote it in Python. What would the SAS code resemble?&lt;BR /&gt;&lt;BR /&gt;As for the cylinders list, it would be:&lt;BR /&gt;&lt;BR /&gt;%let cylinders=(3 cylinders,4 cylinders,5 cylinders,6 cylinders,8 cylinders,10 cylinders,12 cylinders);&lt;BR /&gt;&lt;BR /&gt;Is there a regex to shorten the cylinders list in SAS?</description>
      <pubDate>Wed, 30 Jun 2021 06:04:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751131#M236411</guid>
      <dc:creator>Vicente95</dc:creator>
      <dc:date>2021-06-30T06:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: Use values from an existing column to fill missing values in other columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751132#M236412</link>
      <description>&lt;P&gt;I don't know what the python code does.&lt;/P&gt;
&lt;P&gt;As for the regex, yes SAS can use them, and the macro variable can contain a regex. It just depends how the macro variable is used.&lt;/P&gt;
&lt;P&gt;The other macros variables do not contain a regex, so this one stuck out.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that it'sall regular expressions in python, so I'm unsure why you built the SAS values the way you did.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jun 2021 06:26:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751132#M236412</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-06-30T06:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: Use values from an existing column to fill missing values in other columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751272#M236468</link>
      <description>A lot of what that code is doing is not required in SAS though....you've truncated the code in the picture. I took a quick look at the data and there's no description field in the text so you need to clarify what you're asking for help with. &lt;BR /&gt;Also, since the data is CSV you control the the type and format when importing the data so you can ensure the data is read in correctly.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 30 Jun 2021 14:38:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751272#M236468</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-30T14:38:27Z</dc:date>
    </item>
    <item>
      <title>Re: Use values from an existing column to fill missing values in other columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751279#M236473</link>
      <description>&lt;P&gt;In a nutshell, I am seeking the equivalent SAS code of the following Python code shown below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import re

manufacturer = '(gmc | hyundai | toyota | mitsubishi | ford | chevrolet | ram | buick | jeep | dodge | subaru | nissan | audi | rover  | lexus \
| honda | chrysler | mini | pontiac | mercedes-benz | cadillac | bmw | kia | volvo | volkswagen | jaguar | acura | saturn | mazda | \
mercury | lincoln | infiniti | ferrari | fiat | tesla | land rover | harley-davidson | datsun | alfa-romeo | morgan | aston-martin | porche \
| hennessey)'
condition = '(excellent | good | fair | like new | salvage | new)'
fuel = '(gas | hybrid | diesel |electric)'
title_status = '(clean | lien | rebuilt | salvage | missing | parts only)'
transmission = '(automatic | manual)'
drive = '(4x4 | awd | fwd | rwd | 4wd)'
size = '(mid-size | full-size | compact | sub-compact)'
type_ = '(sedan | truck | SUV | mini-van | wagon | hatchback | coupe | pickup | convertible | van | bus | offroad)'
paint_color = '(red | grey | blue | white | custom | silver | brown | black | purple | green | orange | yellow)'
cylinders = '(\s[1-9] cylinders? |\s1[0-6]? cylinders?)'

keys =    ['manufacturer', 'condition', 'fuel', 'title_status', 'transmission', 'drive','size', 'type', 'paint_color' , 'cylinders']
columns = [ manufacturer,   condition,   fuel,  title_status, transmission ,drive, size, type_, paint_color,   cylinders]

for i,column in zip(keys,columns):
    database[i] = database[i].fillna(
      database['description'].str.extract(column, flags=re.IGNORECASE, expand=False)).str.lower()

database.drop('description', axis=1, inplace= True)&lt;/PRE&gt;&lt;P&gt;I have a large dataset in SAS that has 17 variables of which four are numeric and 13 character/string. The original dataset that I am using can be found here:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://www.kaggle.com/austinreese/craigslist-carstrucks-data" rel="nofollow noreferrer" target="_blank"&gt;https://www.kaggle.com/austinreese/craigslist-carstrucks-data&lt;/A&gt;.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;cylinders&lt;/LI&gt;&lt;LI&gt;condition&lt;/LI&gt;&lt;LI&gt;drive&lt;/LI&gt;&lt;LI&gt;paint_color&lt;/LI&gt;&lt;LI&gt;type&lt;/LI&gt;&lt;LI&gt;manufacturer&lt;/LI&gt;&lt;LI&gt;title_status&lt;/LI&gt;&lt;LI&gt;model&lt;/LI&gt;&lt;LI&gt;fuel&lt;/LI&gt;&lt;LI&gt;transmission&lt;/LI&gt;&lt;LI&gt;description&lt;/LI&gt;&lt;LI&gt;region&lt;/LI&gt;&lt;LI&gt;state&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;price (num)&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;posting_date (num)&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;odometer (num)&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;year (num)&lt;/STRONG&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;After applying specific filters to the numeric columns, there are no missing values for each numeric variable. However, there are thousands to hundreds of thousands of missing variables for the remaining 14 char/string variables. H&lt;SPAN&gt;ow can I write the equivalent SAS code where I use regex on the description column to fill missing values of the other string/char columns with categorical values such as cylinders, condition, drive, paint_color, and so on?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jun 2021 14:58:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751279#M236473</guid>
      <dc:creator>Vicente95</dc:creator>
      <dc:date>2021-06-30T14:58:31Z</dc:date>
    </item>
    <item>
      <title>Re: Use values from an existing column to fill missing values in other columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751287#M236480</link>
      <description>I posted an example in your StackOverflow question - yeah, Kaggle only shows the first few columns by default apparently. But it's just doing a basic text search on the description field so you can just replace it with FIND() or INDEX() and some loops. REGEX is also an option but I hate writing regex so someone else will have to help you with that.&lt;BR /&gt;</description>
      <pubDate>Wed, 30 Jun 2021 15:09:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751287#M236480</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-30T15:09:20Z</dc:date>
    </item>
    <item>
      <title>Re: Use values from an existing column to fill missing values in other columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751289#M236482</link>
      <description>&lt;P&gt;Yes, I received your response. Thank you for that.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jun 2021 15:30:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751289#M236482</guid>
      <dc:creator>Vicente95</dc:creator>
      <dc:date>2021-06-30T15:30:46Z</dc:date>
    </item>
    <item>
      <title>Re: Use values from an existing column to fill missing values in other columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751296#M236485</link>
      <description>&lt;P&gt;For completeness or anyone else looking to tackle this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can expand this by creating an array for each variable and then looping through your lists. I think you can replace the loop with a REGEX command as well in SAS but regex requires too much thinking so someone else will have to provide that answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array _fuel(*) $ _temporary_ ("gas", "hybrid", "diesel", "electric");

do i=1 to dim(_fuel);
if find(description, _fuel(i), 'it')&amp;gt;0 then fuel = _fuel(i);
*does not deal with multiple finds so the last one found will be kept;
end;

run;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Other ways of solving this include making a list of your lookup values and categories such as:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Category Value
Fuel gas
Fuel diesel
Cylinders 1 Cylinder
Cylinders 2 Cylinder
....
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then take your description column and expand it so that each word has it's own row, see example below.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/bed5ea2c12903b38fdcf19f3f1f1aae9" target="_blank"&gt;https://gist.github.com/statgeek/bed5ea2c12903b38fdcf19f3f1f1aae9&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then merge the two via a left join to get your missing values. One benefit of this approach is that you can then use some fuzzy join logic as well which is a bit harder in the direct match approach used above. For example if the post says 1 cyl that won't match to 1 cyl but you could do partial searches. I realized there's actually no regex in your original program except for the cylinders specification and I'm not 100% sure what the fillNA is doing with the matches.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would probably help if you posted a few lines of the data and the output you get from python.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jun 2021 16:01:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751296#M236485</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-30T16:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: Use values from an existing column to fill missing values in other columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751315#M236491</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;

  array columns  manufacturer condition fuel title_status transmission drive size type paint_color  ;
  array strings [9] $300 _temporary_ (
    /*manufacturer*/ 'gmc | hyundai | toyota | mitsubishi | ford | chevrolet | ram | buick | jeep | dodge | subaru | nissan | audi | rover  | lexus 
    | honda | chrysler | mini | pontiac | mercedes-benz | cadillac | bmw | kia | volvo | volkswagen | jaguar | acura | saturn | mazda | 
    mercury | lincoln | infiniti | ferrari | fiat | tesla | land rover | harley-davidson | datsun | alfa-romeo | morgan | aston-martin | porche 
    | hennessey'
    /*condition*/ 'excellent | good | fair | like new | salvage | new'
    /*fuel*/ 'gas | hybrid | diesel |electric'
    /*title_status*/ 'clean | lien | rebuilt | salvage | missing | parts only'
    /*transmission*/ 'automatic | manual'
    /*drive*/ '4x4 | awd | fwd | rwd | 4wd'
    /*size*/ 'mid-size | full-size | compact | sub-compact'
    /*type*/ 'sedan | truck | SUV | mini-van | wagon | hatchback | coupe | pickup | convertible | van | bus | offroad'
    /*paint_color*/ 'red | grey | blue | white | custom | silver | brown | black | purple | green | orange | yellow'
  );
  length word $50 ;
  do col=1 to dim(columns);
    do index=1 to countw(strings[col]),'|') while (missing(columns[col])) ;
      word=left(scan(strings[col],index,'|'));
      if findw(description,word,,'it') then columns[col]=word;
    end;
  end;

  if missing(cylinders) then do;
    index=findw(description,'cylinders',,'it');
    if index then do;
      cylinders=scan(substrn(description,1,index-1),-1)||' cylinders';
    end;
  end;

  drop word col index ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The columns array is the variables that you want to update (when they are missing).&amp;nbsp; The strings temporary array is the list of words for each variable.&lt;/P&gt;
&lt;P&gt;So basically it is finding the first word in the list that it finds in the description.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For cylinders I used a separate step to find where the word cylinders appears and then prefix the last word that appears before that.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jun 2021 17:31:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751315#M236491</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-30T17:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: Use values from an existing column to fill missing values in other columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751319#M236494</link>
      <description>&lt;P&gt;Nice! This is what I was looking for &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; I will try the code and let you know how it goes.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jun 2021 17:43:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751319#M236494</guid>
      <dc:creator>Vicente95</dc:creator>
      <dc:date>2021-06-30T17:43:05Z</dc:date>
    </item>
    <item>
      <title>Re: Use values from an existing column to fill missing values in other columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751367#M236519</link>
      <description>&lt;P&gt;Unfortunately, the code did not work. Do you know what the error messages mean?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;3004  DATA want;
3005      SET have;
3006
3007      array columns  manufacturer condition fuel title_status transmission drive size type paint_color;
3008      array strings [9] $300 _temporary_ (
3009      /*manufacturer*/ 'gmc | hyundai | toyota | mitsubishi | ford | chevrolet | ram | buick | jeep | dodge | subaru | nissan | audi | rover  | lexus
3010      | honda | chrysler | mini | pontiac | mercedes-benz | cadillac | bmw | kia | volvo | volkswagen | jaguar | acura | saturn | mazda |
3011      mercury | lincoln | infiniti | ferrari | fiat | tesla | land rover | harley-davidson | datsun | alfa-romeo | morgan | aston-martin | porche
NOTE: The quoted string currently being processed has become more than 262 characters long.  You might have unbalanced quotation marks.
3012      | hennessey'
3013      /*condition*/ 'excellent | good | fair | like new | salvage | new'
3014      /*fuel*/ 'gas | hybrid | diesel |electric'
3015      /*title_status*/ 'clean | lien | rebuilt | salvage | missing | parts only'
3016      /*transmission*/ 'automatic | manual'
3017      /*drive*/ '4x4 | awd | fwd | rwd | 4wd'
3018      /*size*/ 'mid-size | full-size | compact | sub-compact'
3019      /*type*/ 'sedan | truck | SUV | mini-van | wagon | hatchback | coupe | pickup | convertible | van | bus | offroad'
3020      /*paint_color*/ 'red | grey | blue | white | custom | silver | brown | black | purple | green | orange | yellow'
3021    );
3022
3023    length word $50;
3024    do col=1 to dim(columns);
3025      do index=1 to countw(strings[col]),'|') while (missing(columns[col])) ;
                                                -
                                                388
                                                200
                                                76
ERROR 388-185: Expecting an arithmetic operator.

ERROR 200-322: The symbol is not recognized and will be ignored.

ERROR 76-322: Syntax error, statement will be ignored.

3026        word=left(scan(strings[col],index,'|'));
3027        if findw(description,word,,'it') then columns[col]=word;
3028      end;
3029    end;
3030
3031    if missing(cylinders) then do;
3032      index=findw(description,'cylinders',,'it');
3033      if index then do;
3034        cylinders=scan(substrn(description,1,index-1),-1)||' cylinders';
3035      end;
3036    end;
3037
3038    drop word col index ;
3039  run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Jun 2021 22:43:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751367#M236519</guid>
      <dc:creator>Vicente95</dc:creator>
      <dc:date>2021-06-30T22:43:16Z</dc:date>
    </item>
    <item>
      <title>Re: Use values from an existing column to fill missing values in other columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751368#M236520</link>
      <description>&lt;P&gt;There is an extra closing bracket that shouldn't be there. Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do index=1 to countw(strings[col],'|') while (missing(columns[col])) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jun 2021 23:02:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-values-from-an-existing-column-to-fill-missing-values-in/m-p/751368#M236520</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-06-30T23:02:53Z</dc:date>
    </item>
  </channel>
</rss>

