<?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 How to create multiple variables from a variable with a long raw in SAS in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/How-to-create-multiple-variables-from-a-variable-with-a-long-raw/m-p/877415#M43389</link>
    <description>&lt;P&gt;One variable (device_scan) in my dataset is very long. I would like to create multiple variables using responses in this long variable.&lt;/P&gt;&lt;P&gt;See below example,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Obs&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; device_scan&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {"screenW":1098,"screenH":618,"touch":true,"OS":"Windows","UTCoffset":300}&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{"screenW":1024,"screenH":768,"touch":true,"OS":"MacOS","UTCoffset":240}&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{"screenW":1536,"screenH":864,"touch":true,"OS":"Windows","UTCoffset":300}&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{"screenW":1280,"screenH":1024,"touch":false,"OS":"Windows","UTCoffset":240}&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{"screenW":1080,"screenH":810,"touch":true,"OS":"MacOS","UTCoffset":300}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to create 4 variables using the "device_scan" row:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Device_width (corresponds to response of "screenW":)&lt;/LI&gt;&lt;LI&gt;Device_height (corresponds to response of "screenH":)&lt;/LI&gt;&lt;LI&gt;Touch (corresponds to response of "touch":)&lt;/LI&gt;&lt;LI&gt;Device_OS (corresponds to response of "OS":)&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Wed, 24 May 2023 23:08:23 GMT</pubDate>
    <dc:creator>drchiragvyas</dc:creator>
    <dc:date>2023-05-24T23:08:23Z</dc:date>
    <item>
      <title>How to create multiple variables from a variable with a long raw in SAS</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-to-create-multiple-variables-from-a-variable-with-a-long-raw/m-p/877415#M43389</link>
      <description>&lt;P&gt;One variable (device_scan) in my dataset is very long. I would like to create multiple variables using responses in this long variable.&lt;/P&gt;&lt;P&gt;See below example,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Obs&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; device_scan&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {"screenW":1098,"screenH":618,"touch":true,"OS":"Windows","UTCoffset":300}&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{"screenW":1024,"screenH":768,"touch":true,"OS":"MacOS","UTCoffset":240}&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{"screenW":1536,"screenH":864,"touch":true,"OS":"Windows","UTCoffset":300}&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{"screenW":1280,"screenH":1024,"touch":false,"OS":"Windows","UTCoffset":240}&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{"screenW":1080,"screenH":810,"touch":true,"OS":"MacOS","UTCoffset":300}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to create 4 variables using the "device_scan" row:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Device_width (corresponds to response of "screenW":)&lt;/LI&gt;&lt;LI&gt;Device_height (corresponds to response of "screenH":)&lt;/LI&gt;&lt;LI&gt;Touch (corresponds to response of "touch":)&lt;/LI&gt;&lt;LI&gt;Device_OS (corresponds to response of "OS":)&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2023 23:08:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-to-create-multiple-variables-from-a-variable-with-a-long-raw/m-p/877415#M43389</guid>
      <dc:creator>drchiragvyas</dc:creator>
      <dc:date>2023-05-24T23:08:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to create multiple variables from a variable with a long raw in SAS</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-to-create-multiple-variables-from-a-variable-with-a-long-raw/m-p/877431#M43391</link>
      <description>&lt;P&gt;Looks like JSON.&lt;/P&gt;
&lt;P&gt;It is probably going to be easiest to write the strings to a file and use the JSON libref engine to convert the JSON into dataset(s).&lt;/P&gt;
&lt;P&gt;So if you have this dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input device_scan $80.;
cards;
{"screenW":1098,"screenH":618,"touch":true,"OS":"Windows","UTCoffset":300}
{"screenW":1024,"screenH":768,"touch":true,"OS":"MacOS","UTCoffset":240}
{"screenW":1536,"screenH":864,"touch":true,"OS":"Windows","UTCoffset":300}
{"screenW":1280,"screenH":1024,"touch":false,"OS":"Windows","UTCoffset":240}
{"screenW":1080,"screenH":810,"touch":true,"OS":"MacOS","UTCoffset":300}
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use a data step like this to write an actual JSON file from those strings.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename json temp;
data _null_;
  set have end=eof;
  file json;
  if _n_=1 then put '[' @;
  else put ',' @;
  put device_scan ;
  if eof then put ']';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can use the JSON libref engine to read it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname json json ;
proc print data=json.root;
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-1684986113222.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/84289i1A570ED58DE8C2B1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1684986113222.png" alt="Tom_0-1684986113222.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if instead of having the JSON strings in a dataset you actually already have them in a file with one JSON string per line then what you have is called a JSONL (JSON Lines) file.&amp;nbsp; (There is another acronym people use for that type of file, but it is harder to remember than JSON LINES).&lt;/P&gt;
&lt;PRE&gt;{"screenW":1098,"screenH":618,"touch":true,"OS":"Windows","UTCoffset":300}
{"screenW":1024,"screenH":768,"touch":true,"OS":"MacOS","UTCoffset":240}
{"screenW":1536,"screenH":864,"touch":true,"OS":"Windows","UTCoffset":300}
{"screenW":1280,"screenH":1024,"touch":false,"OS":"Windows","UTCoffset":240}
{"screenW":1080,"screenH":810,"touch":true,"OS":"MacOS","UTCoffset":300}&lt;/PRE&gt;
&lt;P&gt;Then you still need to add the [] and commas to make it back into an actual JSON file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename json temp;
data _null_;
  infile 'myfile.jsonl' end=eof;
  file json;
  if _n_=1 then put '[' @;
  else put ',' @;
  input;
  put _infile_;
  if eof then put ']';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 May 2023 03:50:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-to-create-multiple-variables-from-a-variable-with-a-long-raw/m-p/877431#M43391</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-25T03:50:33Z</dc:date>
    </item>
  </channel>
</rss>

