<?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: Using unknown array dimention to store value from one array to another in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-unknown-array-dimention-to-store-value-from-one-array-to/m-p/384898#M92002</link>
    <description>&lt;P&gt;Well, you can do it in a number of ways, for instance totalling how many there are from metadata and storing in a macro variable. &amp;nbsp;Personally I prefer to use Base SAS, in this case proc transpose. &amp;nbsp;Beinig able to move from normalised data to transposed data and back again is a fundamental modelling technique you should know, and by using this you can avoid the need to "know" how many elements up front, here is an example:&lt;/P&gt;
&lt;PRE&gt;proc format;
  invalue $inf
  1 = 'True'
  2 = 'False'
  3 = 'None'
  4 = 'Invalid';
run;

*Format;
proc format;
  value $res
  'True' = 101
  'False' = 102
  'None' = 103
  'Invalid' = 104;
run;

data ds_user1;
  infile datalines;
  informat value1 value2 value3 $inf.;
  input id $ value1 value2 value3;
datalines;
a 1 2 3
b 2 4 1
c 3 1 4
d 3 3 2
;
run;

proc transpose data=ds_user1 out=t;
  by id;
  var value:;
run;

data t;
  set t;
  _name_=tranwrd(_name_,"value","q");
  col2=put(col1,$res.);
run;

proc transpose data=t out=norm;
  by id;
  var col2;
  id _name_;
  idlabel _name_;
run;

data want (drop=_name_);
  merge ds_user1 norm;
  by id;
run;
&lt;/PRE&gt;
&lt;P&gt;Do note I replaced he use of informat and format as names deliberately, it is really not a good idea to use reserved words for names.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 02 Aug 2017 10:33:50 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-08-02T10:33:50Z</dc:date>
    <item>
      <title>Using unknown array dimention to store value from one array to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-unknown-array-dimention-to-store-value-from-one-array-to/m-p/384895#M91999</link>
      <description>&lt;P&gt;Hi can you help edit my code, I'm using below user defined format and informat to get my value in array, to store values of cards from "value" to "q" variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When i'm using declared varables&amp;nbsp;array as shown below it is working fine, but when i'm changing it to unknown dimention it giving no data in the dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;array value{3} value1 value2 value3;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;array q{3}$ q1 q2 q3;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Informat;
Proc format;
invalue $ informat
1 = 'True'
2 = 'False'
3 = 'None'
4 = 'Invalid';
run;

*Format;
proc format;
value $ format
'True' = 101
'False' = 102
'None' = 103
'Invalid' = 104;
run;

data ds_user1;
infile cards;
retain id value1 value2 value3 q1 q2 q3;
informat value1 value2 value3 $ informat.;
input id$ value1 value2 value3;
array value{*} _numeric_;
array q{*} _character_;
do i=1 to dim(value);
	q{i} = value{i};
end;
format value1 value2 value3 $ format.;
drop i;
cards;
a 1 2 3
b 2 4 1
c 3 1 4
d 3 3 2
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Ayushmaan&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 10:17:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-unknown-array-dimention-to-store-value-from-one-array-to/m-p/384895#M91999</guid>
      <dc:creator>ab12nov</dc:creator>
      <dc:date>2017-08-02T10:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: Using unknown array dimention to store value from one array to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-unknown-array-dimention-to-store-value-from-one-array-to/m-p/384896#M92000</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/155414"&gt;@ab12nov&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;There are that many issues in your code that I really don't know where I would have to start.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given your sample source data, why don't you tell us what you want to achieve.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's your sample data (Remark: OP changed data after I've posted below).&lt;/P&gt;
&lt;PRE&gt;  datalines;
a 1 2 3b 
2 4 1c 3 
1 4d 3 3 2
;
run;&lt;/PRE&gt;
&lt;P&gt;Please show us how your desired result should look like.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 10:29:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-unknown-array-dimention-to-store-value-from-one-array-to/m-p/384896#M92000</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-08-02T10:29:04Z</dc:date>
    </item>
    <item>
      <title>Re: Using unknown array dimention to store value from one array to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-unknown-array-dimention-to-store-value-from-one-array-to/m-p/384898#M92002</link>
      <description>&lt;P&gt;Well, you can do it in a number of ways, for instance totalling how many there are from metadata and storing in a macro variable. &amp;nbsp;Personally I prefer to use Base SAS, in this case proc transpose. &amp;nbsp;Beinig able to move from normalised data to transposed data and back again is a fundamental modelling technique you should know, and by using this you can avoid the need to "know" how many elements up front, here is an example:&lt;/P&gt;
&lt;PRE&gt;proc format;
  invalue $inf
  1 = 'True'
  2 = 'False'
  3 = 'None'
  4 = 'Invalid';
run;

*Format;
proc format;
  value $res
  'True' = 101
  'False' = 102
  'None' = 103
  'Invalid' = 104;
run;

data ds_user1;
  infile datalines;
  informat value1 value2 value3 $inf.;
  input id $ value1 value2 value3;
datalines;
a 1 2 3
b 2 4 1
c 3 1 4
d 3 3 2
;
run;

proc transpose data=ds_user1 out=t;
  by id;
  var value:;
run;

data t;
  set t;
  _name_=tranwrd(_name_,"value","q");
  col2=put(col1,$res.);
run;

proc transpose data=t out=norm;
  by id;
  var col2;
  id _name_;
  idlabel _name_;
run;

data want (drop=_name_);
  merge ds_user1 norm;
  by id;
run;
&lt;/PRE&gt;
&lt;P&gt;Do note I replaced he use of informat and format as names deliberately, it is really not a good idea to use reserved words for names.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 10:33:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-unknown-array-dimention-to-store-value-from-one-array-to/m-p/384898#M92002</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-08-02T10:33:50Z</dc:date>
    </item>
  </channel>
</rss>

