<?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 Problem with Array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-Array/m-p/802089#M315727</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a macro variable var which contains a list of all the numerical dates in my dataset.&lt;/P&gt;
&lt;P&gt;The variable fmt contain the list of&amp;nbsp; format associated with those variables in var.&lt;/P&gt;
&lt;P&gt;The variable newvar is a list of the variables I want to create..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="3"&gt;%put var = &amp;amp;var;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="3"&gt;var = TRTSDT TRTSDTM TRTEDT TRTEDTM DTHDT DCUTDT ASTDT AENDT&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="3"&gt;%put fmt = &amp;amp;fmt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="3"&gt;fmt = E8601DA E8601DT E8601DA E8601DT E8601DA E8601DA E8601DA E8601DA&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="3"&gt;%put newvar = &amp;amp;newvar;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="3"&gt;newvar = TRTSDTC TRTSDTMC TRTEDTC TRTEDTMC DTHDTC DCUTDTC ASTDTC AENDTC&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="3"&gt;I want to create a dataset tat keeps each numerical variable above&amp;nbsp; but also adds the corresponding character variable (date or date time) based on the format.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="3"&gt;I am using an array in a data step but it is not working.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="3"&gt; data adae_new;&lt;BR /&gt;set adae_old;&lt;BR /&gt;array olddt[*] &amp;amp;var.;&lt;BR /&gt;array oldfmt[*] &amp;amp;fmt.;&lt;BR /&gt;array newdtc[*] &amp;amp;newvar.;&lt;BR /&gt;do i = 1 to dim(olddt); &lt;BR /&gt;if oldfmt[i]="E8601DA" then newdtc[i] = put(olddt[i], yymmdd10.); &lt;BR /&gt;else if oldfmt[i]="E8601DT" then newdtc[i] = put(olddt[i], datetime19.);&lt;BR /&gt;drop i;&lt;BR /&gt;end; &lt;BR /&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="3"&gt;This code is not working the character&amp;nbsp;variables&amp;nbsp;are all empty.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="3"&gt;Any suggestions as to how to loop through the list of numerical&amp;nbsp;dates in a dataset and and convert them into character&amp;nbsp;based on the format used ?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 15 Mar 2022 01:43:08 GMT</pubDate>
    <dc:creator>Kc2</dc:creator>
    <dc:date>2022-03-15T01:43:08Z</dc:date>
    <item>
      <title>Problem with Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-Array/m-p/802089#M315727</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a macro variable var which contains a list of all the numerical dates in my dataset.&lt;/P&gt;
&lt;P&gt;The variable fmt contain the list of&amp;nbsp; format associated with those variables in var.&lt;/P&gt;
&lt;P&gt;The variable newvar is a list of the variables I want to create..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="3"&gt;%put var = &amp;amp;var;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="3"&gt;var = TRTSDT TRTSDTM TRTEDT TRTEDTM DTHDT DCUTDT ASTDT AENDT&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="3"&gt;%put fmt = &amp;amp;fmt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="3"&gt;fmt = E8601DA E8601DT E8601DA E8601DT E8601DA E8601DA E8601DA E8601DA&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="3"&gt;%put newvar = &amp;amp;newvar;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="3"&gt;newvar = TRTSDTC TRTSDTMC TRTEDTC TRTEDTMC DTHDTC DCUTDTC ASTDTC AENDTC&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="3"&gt;I want to create a dataset tat keeps each numerical variable above&amp;nbsp; but also adds the corresponding character variable (date or date time) based on the format.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="3"&gt;I am using an array in a data step but it is not working.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="3"&gt; data adae_new;&lt;BR /&gt;set adae_old;&lt;BR /&gt;array olddt[*] &amp;amp;var.;&lt;BR /&gt;array oldfmt[*] &amp;amp;fmt.;&lt;BR /&gt;array newdtc[*] &amp;amp;newvar.;&lt;BR /&gt;do i = 1 to dim(olddt); &lt;BR /&gt;if oldfmt[i]="E8601DA" then newdtc[i] = put(olddt[i], yymmdd10.); &lt;BR /&gt;else if oldfmt[i]="E8601DT" then newdtc[i] = put(olddt[i], datetime19.);&lt;BR /&gt;drop i;&lt;BR /&gt;end; &lt;BR /&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="3"&gt;This code is not working the character&amp;nbsp;variables&amp;nbsp;are all empty.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="3"&gt;Any suggestions as to how to loop through the list of numerical&amp;nbsp;dates in a dataset and and convert them into character&amp;nbsp;based on the format used ?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 01:43:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-Array/m-p/802089#M315727</guid>
      <dc:creator>Kc2</dc:creator>
      <dc:date>2022-03-15T01:43:08Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-Array/m-p/802094#M315728</link>
      <description>&lt;P&gt;If you going to put character strings into the new variables then they need to be defined as character.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array newdtc[*] $19 &amp;amp;newvar.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do you really have variables named&amp;nbsp;&amp;nbsp;E8601DA E8601DT etc?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data adae_new;
  set adae_old;
  array olddt[*] &amp;amp;var.;
  array newdtc[*] $19 &amp;amp;newvar.;
  do i = 1 to dim(olddt);
    if scan("&amp;amp;fmt",i,' ')="E8601DA" then newdtc[i] = put(olddt[i], yymmdd10.);
    else newdtc[i] = put(olddt[i], datetime19.);
  end;
  drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Mar 2022 02:31:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-Array/m-p/802094#M315728</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-15T02:31:33Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-Array/m-p/802167#M315782</link>
      <description>&lt;P&gt;Thank you Tom, it worked.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not have&amp;nbsp; variables&amp;nbsp; named&amp;nbsp; &lt;SPAN&gt;&amp;nbsp;E8601DA E8601DT&amp;nbsp;&lt;/SPAN&gt;. I created a list of numerical variable and their associated format using a proc sql. I then assigned the format and the variables to a macro variable.&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table ds0 as&lt;BR /&gt;select libname, memname, name, type, length, label, format &lt;BR /&gt;from dictionary.columns&lt;BR /&gt;where libname='WORK' and type='num' and upcase(label) like '%DATE%';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select name into :var separated by ' '&lt;BR /&gt;from ds0 ;&lt;/P&gt;
&lt;P&gt;select scan(format,1,'.') into :fmt separated by ' '&lt;BR /&gt;from ds0 ;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;which gives&lt;/P&gt;
&lt;P&gt;var = TRTSDT TRTSDTM TRTEDT TRTEDTM DTHDT DCUTDT ASTDT AENDT&lt;BR /&gt;fmt = E8601DA E8601DT E8601DA E8601DT E8601DA E8601DA E8601DA E8601DA.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to order the newly created variables dynamically next to their numerical counterpart instead of doing it for each datasets manually ?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 12:46:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-Array/m-p/802167#M315782</guid>
      <dc:creator>Kc2</dc:creator>
      <dc:date>2022-03-15T12:46:01Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-Array/m-p/802181#M315791</link>
      <description>&lt;P&gt;In order&amp;nbsp; to dynamically order the new character variables next to the numerical ones. I am using the varnum variable.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have these macro variables;&lt;/P&gt;
&lt;P&gt;var = TRTSDT TRTSDTM TRTEDT TRTEDTM DTHDT DCUTDT ASTDT AENDT&lt;BR /&gt;fmt = E8601DA E8601DT E8601DA E8601DT E8601DA E8601DA E8601DA E8601DA&lt;BR /&gt;newvar = TRTSDTC TRTSDTMC TRTEDTC TRTEDTMC DTHDTC DCUTDTC ASTDTC AENDTC&lt;BR /&gt;pos = 45 46 47 48 53 54 61 67&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data adae0;&lt;BR /&gt;set adae_copy;&lt;BR /&gt;array varnum[*] &amp;amp;pos.;&lt;BR /&gt;array olddt[*] &amp;amp;var.;&lt;BR /&gt;array newdtc[*] $19 &amp;amp;newvar.;&lt;BR /&gt;&lt;BR /&gt;do i = 1 to dim(olddt); &lt;BR /&gt;if scan("&amp;amp;fmt",i,' ')="E8601DA" then newdtc[i] = put(olddt[i], yymmdd10.);&lt;BR /&gt;else newdtc[i] = put(olddt[i], datetime19.);&lt;BR /&gt;varnum[i] = input(&amp;amp;pos[i],8.)+ 0.5;&lt;BR /&gt;end; &lt;BR /&gt;drop i;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get the error messages;&lt;/P&gt;
&lt;P&gt;array varnum[*] &amp;amp;pos.;-&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 79&lt;/P&gt;
&lt;P&gt;ERROR 79-322: Expecting a ).&lt;/P&gt;
&lt;P&gt;ERROR: The array varnum has been defined with zero elements.&lt;BR /&gt;ERROR: Too many array subscripts specified for array varnum.&lt;BR /&gt;NOTE: Line generated by the macro variable "POS".&lt;BR /&gt;&amp;nbsp;45 46 47 48 53 54 61 67&lt;BR /&gt;--&lt;BR /&gt;388&lt;BR /&gt;76&lt;/P&gt;
&lt;P&gt;ERROR 352-185: The length of numeric variables is 3-8.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given that the array are by default numeric, I do not understand the issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 13:18:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-Array/m-p/802181#M315791</guid>
      <dc:creator>Kc2</dc:creator>
      <dc:date>2022-03-15T13:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-Array/m-p/802207#M315796</link>
      <description>&lt;P&gt;You need to figure out what SAS code you want to run before you start trying to use code generation to create the code from data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The order of the variables in the dataset is determined by the order they appear in the data step.&amp;nbsp; So you need something that lists the variables in the order you want them at the top of your program.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sometimes you can use a RETAIN statement since that will set the variables location in the dataset, but it does not force a particular type/length for the variable.&amp;nbsp; But be careful that retaining the variable does not cause issues with how you are populating it.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you could generate a LENGTH statement (or ATTRIB statements) that actually defines the variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So is the goal to generate a character translations of every DATE or DATETIME variable in the source dataset?&amp;nbsp; Is the pattern to add the letter C to the end of the existing variable's name?&amp;nbsp; So the character version of XXX would be in XXXC?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Get the list of variables.&amp;nbsp; I will use PROC CONTENTS because then the FORMAT variable contains just the name of the format instead of the full format specification that is shown in DICTIONARY.COLUMNS.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=have noprint out=names(keep=libname memname varnum name type length format) ;
run;
proc sort data=names;
  by varnum;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can use that to generate new variable definitions.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new_names;
  set names;
  length fmtcat $8;
  fmtcat=fmtinfo(format,'cat');
  output;
  if fmtcat in ('date','datetime') then do;
    varnum=varnum+0.5;
    name=cats(name,'C')
    type=2;
    if fmtcat='date' then length=10;
    else length=18;
    output;
  end;
run;  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can use that to generate a LENGTH statement for ALL of the variables, new and old.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename length temp;
data _null_;
  set new_names end=eof;
  file length;
  if _n_=1 then put 'length';
  put @3 name @;
  if type=2 then put '$' @;
  put length ;
  if eof then put ';';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And a series of assignment statements to create the new "C" variables.&amp;nbsp; The -L modifier on the datetime format specification is to handle the bug in the DATETIME format.&amp;nbsp; You should be able to display 9 character date and 8 character time with a colon separator in 18 characters.&amp;nbsp; But if you use DATETIME18. you only get 2 digit years.&amp;nbsp; If you use DATETIME19. you get four digit years, but a leading spaces.&amp;nbsp; So the -L will left align the 18 characters so it moves the space to the end.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename dates temp;
data _null_;
  set new_names;
  file dates;
  if type=2 and fmtcat in ('date','datetime') then do;
     put name '=put(' name +(-2) ',' @;
     if fmtcat='date' then put 'yymmdd10.' @;
     else put 'datetime19.-L' @;
     put ');';
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can use those two files with the LENGTH statement and the series of assignment statements in a new data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
%include length / source2;
  set have;
%include dates / source2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 14:03:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-Array/m-p/802207#M315796</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-15T14:03:25Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-Array/m-p/802211#M315798</link>
      <description>&lt;P&gt;Thanks Tom,&lt;/P&gt;
&lt;P&gt;I will try out the code you shared.&lt;/P&gt;
&lt;P&gt;I have a folder with 20 datasets. I need to loop through each datasets and create a character version of the dates variables.&lt;/P&gt;
&lt;P&gt;XXX becomes XXXC&lt;/P&gt;
&lt;P&gt;I need the character variables in the datasets to be next to their numeric part XXX XXC.&lt;/P&gt;
&lt;P&gt;and have the correct format used when converting from numeric to character: date or datetime.&lt;/P&gt;
&lt;P&gt;The macro I coded does everything except the ordering (your suggestion to declare the array as character helped.)&lt;/P&gt;
&lt;P&gt;For reviewing purposes we need the numeric variables and the character variables next to each other.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 14:14:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-Array/m-p/802211#M315798</guid>
      <dc:creator>Kc2</dc:creator>
      <dc:date>2022-03-15T14:14:46Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-Array/m-p/802291#M315828</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;
&lt;P&gt;I update my code with your suggestion.&lt;/P&gt;
&lt;P&gt;the iterative loop to go through each dataset in the work directory&amp;nbsp; is instead counting the number of variables&lt;/P&gt;
&lt;P&gt;&amp;nbsp;of each dataset.&lt;/P&gt;
&lt;P&gt;Do you know why the &amp;nbsp;%do %while (&amp;amp;iter.&amp;lt;= &amp;amp;dscnt.); loop is going through the variable and not the datasets. (ADSL, ADAE, ADCM, ADLB,etc..)&lt;/P&gt;
&lt;P&gt;I have 10 datasets and each dataset has 8 numeric dates variables that need to have their corresponding character variables created.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro loopOverDs(indir=); &lt;BR /&gt;%*--- loop through all SAS datasets and add character dates to numerical dates;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table datelist as&lt;BR /&gt;select libname, memname, name, type, length, label, format, varnum&lt;BR /&gt;from dictionary.columns&lt;BR /&gt;where libname='WORK' and type='num' and upcase(label) like '%DATE%';&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;%*--- get number of datasets;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;select count (distinct memname)&lt;BR /&gt;into :dscnt&lt;BR /&gt;from datelist;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;%put datasets= &amp;amp;dscnt.;&lt;/P&gt;
&lt;P&gt;%*--- initiate loop;&lt;BR /&gt;%let iter=1;&lt;BR /&gt;&lt;BR /&gt;%do %while (&amp;amp;iter.&amp;lt;= &amp;amp;dscnt.);&lt;BR /&gt;%*--- getting libref and dataset name for dataset to work on during this iteration;&lt;BR /&gt;data _null_;&lt;BR /&gt;set datelist (firstobs=&amp;amp;iter. obs=&amp;amp;iter.); *only read 1 record;&lt;BR /&gt;call symput("inMember",strip(memname));&lt;BR /&gt;run;&lt;BR /&gt;%put inMember= &amp;amp;inMember.;&lt;/P&gt;
&lt;P&gt;%*--- Subsetting the dataset to keep only vars on interest;&lt;BR /&gt;data ds0(rename=(typen=type)); &lt;BR /&gt;set datelist;&lt;BR /&gt;where memname="&amp;amp;inMember.";&lt;BR /&gt;format=scan(format,1,'.');&lt;BR /&gt;if type="num" then typen=1;&lt;BR /&gt;drop type memname;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%*--- getting number of variable and names of character date variable to convert into numeric;&lt;BR /&gt;proc sql noprint ;&lt;BR /&gt;select count(distinct name )into :varnum &lt;BR /&gt;from ds0 ;&lt;/P&gt;
&lt;P&gt;select name into :var separated by ' '&lt;BR /&gt;from ds0 ;&lt;/P&gt;
&lt;P&gt;select scan(format,1,'.') into :fmt separated by ' '&lt;BR /&gt;from ds0 ;&lt;/P&gt;
&lt;P&gt;select catx("",name,"C") into :newvar separated by ' '&lt;BR /&gt;from ds0 ;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;%put varnum = &amp;amp;varnum;&lt;BR /&gt;%put var = &amp;amp;var;&lt;BR /&gt;%put fmt = &amp;amp;fmt;&lt;BR /&gt;%put newvar = &amp;amp;newvar;&lt;BR /&gt;&lt;BR /&gt;/* data new_names;&lt;BR /&gt;set ds0;&lt;BR /&gt;length fmtcat $8;&lt;BR /&gt;fmtcat=fmtinfo(format,'cat');&lt;BR /&gt;output;&lt;BR /&gt;if fmtcat in ('date','datetime') then do;&lt;BR /&gt;varnum=varnum+0.5;&lt;BR /&gt;name=cats(name,'C');&lt;BR /&gt;type=2;&lt;BR /&gt;if fmtcat='date' then length=10;&lt;BR /&gt;else length=18;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;filename length temp;&lt;BR /&gt;data _null_;&lt;BR /&gt;set new_names end=eof;&lt;BR /&gt;file length;&lt;BR /&gt;if _n_=1 then put 'length';&lt;BR /&gt;put @3 name @;&lt;BR /&gt;if type=2 then put '$' @;&lt;BR /&gt;put length ;&lt;BR /&gt;if eof then put ';';&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;filename dates temp;&lt;BR /&gt;data _null_;&lt;BR /&gt;set new_names;&lt;BR /&gt;file dates;&lt;BR /&gt;if type=2 and fmtcat in ('date','datetime') then do;&lt;BR /&gt;put name '=put(' name +(-2) ',' @;&lt;BR /&gt;if fmtcat='date' then put 'yymmdd10.' @;&lt;BR /&gt;else put 'datetime19.-L' @;&lt;BR /&gt;put ');';&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data &amp;amp;inMember._upd;&lt;BR /&gt;/* %include length / source2;*/&lt;BR /&gt;set &amp;amp;inMember.;&lt;BR /&gt;/* %include dates / source2;*/&lt;/P&gt;
&lt;P&gt;array olddt[*] &amp;amp;var.;&lt;BR /&gt;array newdtc[*] $19 &amp;amp;newvar.;&lt;BR /&gt;&lt;BR /&gt;do i = 1 to dim(olddt); &lt;BR /&gt;if scan("&amp;amp;fmt",i,' ')="E8601DA" then newdtc[i] = put(olddt[i], yymmdd10.);&lt;BR /&gt;else newdtc[i] = put(olddt[i], datetime19.);&lt;BR /&gt;end; &lt;BR /&gt;drop i;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%*--- increment the iterator of the loop;&lt;BR /&gt;%let iter=%eval(&amp;amp;iter.+1);&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;%*--- call the macro;&lt;BR /&gt;%loopOverDs(indir=work);&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 17:38:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-Array/m-p/802291#M315828</guid>
      <dc:creator>Kc2</dc:creator>
      <dc:date>2022-03-15T17:38:57Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-Array/m-p/802295#M315831</link>
      <description>&lt;P&gt;If you want to iterate then just have the DO loop iterate instead of using a WHILE() loop and having to increment the counter by hand.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%*--- get dataset list;
proc sql noprint;
select distinct nliteral(memname)
  into :dslist separated by ' '
  from datelist
;
quit;
%let dscnt=&amp;amp;sqlobs;

%*--- loop over datsaets ;
%do iter=1 %to &amp;amp;dscnt;
  %let inMember=%scan(&amp;amp;dslist,&amp;amp;iter,%str( ),q);
  %put &amp;amp;=inMember;

... Code to process one member ...

%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 17:52:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-Array/m-p/802295#M315831</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-15T17:52:16Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-Array/m-p/802305#M315836</link>
      <description>&lt;P&gt;thank you Tom it solve my problem.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 18:12:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-Array/m-p/802305#M315836</guid>
      <dc:creator>Kc2</dc:creator>
      <dc:date>2022-03-15T18:12:32Z</dc:date>
    </item>
  </channel>
</rss>

