<?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 can I set the length of a column before proc transpose? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-set-the-length-of-a-column-before-proc-transpose/m-p/862692#M340767</link>
    <description>&lt;P&gt;So you are saying the values in the JSON text are too long to use as variable names?&lt;/P&gt;
&lt;P&gt;If so then use them as the variable LABEL instead.&amp;nbsp; Create a different variable to use as the variable NAME.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If nothing else you can just number them like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data alldata;
  set json.alldata end=eof;
  where v&amp;gt;0;
  by p1 notsorted;
  length variable $32 ;
  if _n_=1 then do;
     declare hash h();
     rc=h.definekey('p2');
     rc=h.definedata('variable','varnum','p2');
     rc=h.definedone();
  end;
  if h.find() then do;
    varnum+1;
    variable=cats('var',varnum);
    rc=h.add();
  end;
  if eof then rc=h.output(dataset:'allvars');
run;

proc print data=allvars;
run;

proc transpose data=alldata out=want(drop=_name_);
  by p1 notsorted ;
  id variable;
  idlabel p2 ;
  var value ;
run;

proc print;
run;

proc print label;
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-1678204314622.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81158i49DA4E2465F6936C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1678204314622.png" alt="Tom_0-1678204314622.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>Tue, 07 Mar 2023 15:52:03 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-03-07T15:52:03Z</dc:date>
    <item>
      <title>How can I set the length of a column before proc transpose?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-set-the-length-of-a-column-before-proc-transpose/m-p/862653#M340754</link>
      <description>&lt;P&gt;Hello everybody,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a handful of JSON files that I can now transform automatically into datasets, in part thanks to&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/How-can-I-transform-JSON-multiple-tables-into-a-single-DS-in-SAS/m-p/861099/highlight/true#M340152" target="_blank" rel="noopener"&gt;this link&lt;/A&gt;&amp;nbsp;and in part thanks to some documentation on macros and loops. The thing is that I'm transposing the files, groped by the first data column (p1) from the ALLDATA table and, in a couple of files, some of the variables in p1 are being truncated as they have more than 32 characters, making them duplicates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just to make it clear, they are NOT variable names. They are observations and my guess is that either while reading the JSON files or while transposing them they are treated as variables. Otherwise I understand that they would be as long as the largest one... right?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The user that helped me with that in that post, also gave me solution to this but I can only use it when I know the variables the JSON has. In my case, there will be hundreds of JSON files each with its own variables. They will all have something in common and that is their tree structure so I will call the ALLDATA p1 variable the same way every time. Is there any way of using a data step to format the length of just the first column and leave the rest as they are? Here's the code he suggested to do that when knowing the variables beforehand:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data want;
  length
    category $32
    location $100
    speed $20
    idCategory $10
    speedMBps 8
    timeFixedPrice $10
    includedDiscount 8
  ;
  set json.category: indsname=indsname;
  category=scan(indsname,-1,'.');
  drop ordinal_: ;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks in advance!!!&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2023 13:12:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-set-the-length-of-a-column-before-proc-transpose/m-p/862653#M340754</guid>
      <dc:creator>caracena</dc:creator>
      <dc:date>2023-03-07T13:12:19Z</dc:date>
    </item>
    <item>
      <title>Re: How can I set the length of a column before proc transpose?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-set-the-length-of-a-column-before-proc-transpose/m-p/862692#M340767</link>
      <description>&lt;P&gt;So you are saying the values in the JSON text are too long to use as variable names?&lt;/P&gt;
&lt;P&gt;If so then use them as the variable LABEL instead.&amp;nbsp; Create a different variable to use as the variable NAME.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If nothing else you can just number them like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data alldata;
  set json.alldata end=eof;
  where v&amp;gt;0;
  by p1 notsorted;
  length variable $32 ;
  if _n_=1 then do;
     declare hash h();
     rc=h.definekey('p2');
     rc=h.definedata('variable','varnum','p2');
     rc=h.definedone();
  end;
  if h.find() then do;
    varnum+1;
    variable=cats('var',varnum);
    rc=h.add();
  end;
  if eof then rc=h.output(dataset:'allvars');
run;

proc print data=allvars;
run;

proc transpose data=alldata out=want(drop=_name_);
  by p1 notsorted ;
  id variable;
  idlabel p2 ;
  var value ;
run;

proc print;
run;

proc print label;
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-1678204314622.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81158i49DA4E2465F6936C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1678204314622.png" alt="Tom_0-1678204314622.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>Tue, 07 Mar 2023 15:52:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-set-the-length-of-a-column-before-proc-transpose/m-p/862692#M340767</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-07T15:52:03Z</dc:date>
    </item>
    <item>
      <title>Re: How can I set the length of a column before proc transpose?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-set-the-length-of-a-column-before-proc-transpose/m-p/862802#M340808</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;thanks again. You are a genius and a life saver. I owe you two beers now &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2023 20:51:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-set-the-length-of-a-column-before-proc-transpose/m-p/862802#M340808</guid>
      <dc:creator>caracena</dc:creator>
      <dc:date>2023-03-07T20:51:52Z</dc:date>
    </item>
  </channel>
</rss>

