<?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: label many columns from _YY_MM_DD  to YY/MM/DD in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/label-many-columns-from-YY-MM-DD-to-YY-MM-DD/m-p/634208#M188232</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;But if you use PROC REPORT, you don't have to go through the programming effort to modify labels.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Agreed, or at least not more than one.&lt;/P&gt;
&lt;P&gt;But since OP has not provided an example of the data structure he currently has or exactly what the output should be a bit of shooting in the dark.&lt;/P&gt;</description>
    <pubDate>Mon, 23 Mar 2020 18:46:17 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-03-23T18:46:17Z</dc:date>
    <item>
      <title>label many columns from _YY_MM_DD  to YY/MM/DD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/label-many-columns-from-YY-MM-DD-to-YY-MM-DD/m-p/634144#M188212</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have the following problem.&lt;/P&gt;
&lt;P&gt;I am using many source data sets in order to create one summary data set.&lt;/P&gt;
&lt;P&gt;In the&amp;nbsp; summary data set there are many columns with names structure _YY_MM_DD .&lt;/P&gt;
&lt;P&gt;I wish that I could give names with structure YY/MM/DD&amp;nbsp; but in SAS it is not possible so I decided to give names with structure _YY_MM_DD.&lt;/P&gt;
&lt;P&gt;I would like to use proc print in order to print the summary data set.&lt;/P&gt;
&lt;P&gt;My question is how to label the culumns from structure _YY_MM_DD&amp;nbsp; to YY/MM/DD?&lt;/P&gt;
&lt;P&gt;Since there are many columns (300 columns) I am looking for a useful method to do it and not write it manually in label statement withing proc print.&lt;/P&gt;
&lt;P&gt;Any idea?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2020 14:59:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/label-many-columns-from-YY-MM-DD-to-YY-MM-DD/m-p/634144#M188212</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-03-23T14:59:52Z</dc:date>
    </item>
    <item>
      <title>Re: label many columns from _YY_MM_DD  to YY/MM/DD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/label-many-columns-from-YY-MM-DD-to-YY-MM-DD/m-p/634147#M188214</link>
      <description>&lt;P&gt;As I think about this problem, it seems to me that this is a case where a LONG data set would work much much much much much much&amp;nbsp;much much much much much much&amp;nbsp;much much much much much much&amp;nbsp;much much much much much much better than a wide data set. On each row, you could have the actual SAS date (not _YY_MM_DD but a true SAS date value such as 21997, optionally formatted any way you would like) and whatever data you want for that date. Then PROC REPORT can produce the necessary YY/MM/DD column headings with very little programming effort, although I sincerely question the value of a PROC PRINT or PROC REPORT with 300 columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Important concept: your SAS data set does not have to be in the form you want it printed. It can be in a very different form, and then the reporting procedure (PROC PRINT, PROC TABULATE, PROC REPORT) can make it appear in the form you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Adding: PROC TRANSPOSE can turn your wide data set into the necessary long data set.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2020 15:15:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/label-many-columns-from-YY-MM-DD-to-YY-MM-DD/m-p/634147#M188214</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-03-23T15:15:27Z</dc:date>
    </item>
    <item>
      <title>Re: label many columns from _YY_MM_DD  to YY/MM/DD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/label-many-columns-from-YY-MM-DD-to-YY-MM-DD/m-p/634165#M188218</link>
      <description>&lt;P&gt;I agree with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; about the usefulness of 300 columns with that sort of label.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The basic approach is to get the names of the variables and the current label into a data set. Then you can use a data step with call execute to make a call to Proc Datasets to change the labels with the Modify statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A similar question with the key elements is answered here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/How-do-I-create-labels-for-more-than-400-variables/m-p/254070" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/How-do-I-create-labels-for-more-than-400-variables/m-p/254070&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2020 16:31:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/label-many-columns-from-YY-MM-DD-to-YY-MM-DD/m-p/634165#M188218</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-23T16:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: label many columns from _YY_MM_DD  to YY/MM/DD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/label-many-columns-from-YY-MM-DD-to-YY-MM-DD/m-p/634166#M188219</link>
      <description>&lt;P&gt;But if you use PROC REPORT, you don't have to go through the programming effort to modify labels.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2020 16:36:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/label-many-columns-from-YY-MM-DD-to-YY-MM-DD/m-p/634166#M188219</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-03-23T16:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: label many columns from _YY_MM_DD  to YY/MM/DD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/label-many-columns-from-YY-MM-DD-to-YY-MM-DD/m-p/634167#M188220</link>
      <description>How did you get to that data set? Did you have it in a long format initially and then PROC TRANSPOSE flipped it?&lt;BR /&gt;If so, there's a method in that step to ensure you get the appropriate labels in a single step. I would recommend that approach to fix it as well since it's dynamic. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 23 Mar 2020 16:37:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/label-many-columns-from-YY-MM-DD-to-YY-MM-DD/m-p/634167#M188220</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-03-23T16:37:13Z</dc:date>
    </item>
    <item>
      <title>Re: label many columns from _YY_MM_DD  to YY/MM/DD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/label-many-columns-from-YY-MM-DD-to-YY-MM-DD/m-p/634173#M188223</link>
      <description>&lt;P&gt;Here's two methods. The first uses PROC TRANSPOSE and the second uses PROC DATASETS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*create dummy data;
data have;
	array _dates(31) _2020_01_01 - _2020_01_31;

	do ID=1 to 100;

		do i=1 to dim(_dates);
			_dates(i)=rand('integer', 0, 100);
		end;
		output;
	end;
	drop i;
run;

*transpose to long format;
proc transpose data=have out=_long;
	by ID;
run;

*add label string;
data _long2;
	set _long;
	*create label;
	label_str=input(compress(_name_, "_"), yymmdd8.);
	format label_str yymmdds10.;
run;

*transpose to wide format;
proc transpose data=_long2 out=wide (drop=_name_);
	by ID;
	id _name_;
	idlabel label_str;
	var col1;
run;

*display output;
proc print data=wide (obs=10) label;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This one is better if you have large data set and want to make changes in place. This does not manipulate the data in any manner, it adds the labels to the data set metadata instead and is ready to use when you use the data set.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	*set input data, just one observation;
	set have (obs=1);
	*set list of dates to add labels to;
	array _dates(*) _:;
	length label_statement $30.;
	*start proc data sets, have is input data modify here if necessary;
	call execute('proc datasets lib=work nodetails nolist; modify have; label');

	do i=1 to dim(_dates);
		*name of variable;
		str1=vname(_dates(i));
		*label for date;
		str_label=put(input(compress(str1, "_"), yymmdd8.), yymmdds10.);
		*create string for relabel eg _2020_01_30 = "2020/01/30";
		label_statement=catt(str1, '=', quote(str_label));
		*run the command;
		call execute(label_statement);
	end;
	*close proc datasets;
	call execute(";run;quit;");
run;

*display output;

proc print data=have (obs=10) label;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have the following problem.&lt;/P&gt;
&lt;P&gt;I am using many source data sets in order to create one summary data set.&lt;/P&gt;
&lt;P&gt;In the&amp;nbsp; summary data set there are many columns with names structure _YY_MM_DD .&lt;/P&gt;
&lt;P&gt;I wish that I could give names with structure YY/MM/DD&amp;nbsp; but in SAS it is not possible so I decided to give names with structure _YY_MM_DD.&lt;/P&gt;
&lt;P&gt;I would like to use proc print in order to print the summary data set.&lt;/P&gt;
&lt;P&gt;My question is how to label the culumns from structure _YY_MM_DD&amp;nbsp; to YY/MM/DD?&lt;/P&gt;
&lt;P&gt;Since there are many columns (300 columns) I am looking for a useful method to do it and not write it manually in label statement withing proc print.&lt;/P&gt;
&lt;P&gt;Any idea?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2020 17:03:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/label-many-columns-from-YY-MM-DD-to-YY-MM-DD/m-p/634173#M188223</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-03-23T17:03:11Z</dc:date>
    </item>
    <item>
      <title>Re: label many columns from _YY_MM_DD  to YY/MM/DD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/label-many-columns-from-YY-MM-DD-to-YY-MM-DD/m-p/634208#M188232</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;But if you use PROC REPORT, you don't have to go through the programming effort to modify labels.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Agreed, or at least not more than one.&lt;/P&gt;
&lt;P&gt;But since OP has not provided an example of the data structure he currently has or exactly what the output should be a bit of shooting in the dark.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2020 18:46:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/label-many-columns-from-YY-MM-DD-to-YY-MM-DD/m-p/634208#M188232</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-23T18:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: label many columns from _YY_MM_DD  to YY/MM/DD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/label-many-columns-from-YY-MM-DD-to-YY-MM-DD/m-p/634400#M188275</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id _20_01_01 _20_01_02;
cards;
1 2 3
2 4 6
;
proc transpose data=have(obs=0) out=temp;
var _all_;
run;
data temp;
 set temp;
 if _name_ =: '_' then label=translate(substr(_name_,2),'/','_');
  else label=_name_;
run;
data _null_;
 set temp end=last;
 if _n_=1 then 
call execute('proc datasets library=work nolist nodetails;modify have;label ');
call execute(cats(_name_,'="',label,'"'));
if last then call execute(';quit;');
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Mar 2020 11:11:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/label-many-columns-from-YY-MM-DD-to-YY-MM-DD/m-p/634400#M188275</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-03-24T11:11:05Z</dc:date>
    </item>
    <item>
      <title>Re: label many columns from _YY_MM_DD  to YY/MM/DD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/label-many-columns-from-YY-MM-DD-to-YY-MM-DD/m-p/634412#M188282</link>
      <description>Are you talking about the labels attached to the variables or the names of the variables?  You can use any text you want for the labels.</description>
      <pubDate>Tue, 24 Mar 2020 12:35:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/label-many-columns-from-YY-MM-DD-to-YY-MM-DD/m-p/634412#M188282</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-24T12:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: label many columns from _YY_MM_DD  to YY/MM/DD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/label-many-columns-from-YY-MM-DD-to-YY-MM-DD/m-p/634415#M188285</link>
      <description>&lt;P&gt;As others already pointed out it's likely best to revisit the process which creates this data structure and variable names in first place.&lt;/P&gt;
&lt;P&gt;But to just provide a solution for how I understand your question below code adds labels to variable which follow the naming convention of &lt;EM&gt;_yy_mm_dd&lt;/EM&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.have;
  array vars {*} 8 _20_01_01 - _20_01_20 (20*1);
  output;
  stop;
run;

%macro _addLable(ds);
  %let ds=%upcase(&amp;amp;ds);
  %local _lref _tbl;
  %let _lref=%scan(WORK.&amp;amp;ds,-2);
  %let _tbl=%scan(&amp;amp;ds,-1);
  proc sql;
    create view _v_varlist as
    select name, input(compress(name,,'kd'),yymmdd6.) as name_dt
    from dictionary.columns
    where libname="&amp;amp;_lref" and memname="&amp;amp;_tbl"
      and prxmatch('/^_\d\d_\d\d_\d\d$/oi',strip(name));
    ;
  quit;

  filename codegen temp;
  data _null_;
  /*  file print;*/
    file codegen;
    set _v_varlist end=last;
    if _n_=1 then 
      do;
        put
          "proc datasets lib=&amp;amp;_lref nolist nowarn;" /
          "  modify &amp;amp;_tbl;" /
          '    label'
          ;
      end;
        put @6 name "='" name_dt yymmdds10. "'";
      if last then
        do;
          put 
            @7 ';' /
            @3 'run;' /
            @1 'quit;'
            ;
        end;
      ;
  run;

  %include codegen / source2;
  filename codegen clear;
%mend;

%_addLable(have)

proc print data=have label;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Mar 2020 12:47:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/label-many-columns-from-YY-MM-DD-to-YY-MM-DD/m-p/634415#M188285</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-03-24T12:47:10Z</dc:date>
    </item>
  </channel>
</rss>

