<?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 Generater_proc_SQL_and_REPORT in SAS Users Group in Israel</title>
    <link>https://communities.sas.com/t5/SAS-Users-Group-in-Israel/Generater-proc-SQL-and-REPORT/m-p/650148#M30</link>
    <description>&lt;P&gt;קטע הקוד הבא יהיה שימושי במיוחד לעצלנים כמוני &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;התכנית לוקחת טבלה מסוימת ומייצר ממנה בסיס קוד ניתן לעריכה עבור פרוצדורות SQL + REPORT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let lib 		=sashelp;
%let memname 	=class;
%let out_path 	=c:\temp;

/*---------------------------------------------------------------------------------------------------------------------------------------------*/
/* GET Dictionary */
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
proc sql;
	create table vars as
	select * /*varnum, name*/
	from dictionary.columns
	where libname=UPCASE("&amp;amp;lib") and memname = UPCASE("&amp;amp;memname")
	;
quit;

proc sql noprint;
	select distinct lowcase(name)
	into :orderedvars separated by ','
	from vars
	order by varnum;
quit;

proc sql noprint;
	select distinct lowcase(name)
	into :reportvars separated by ' '
	from vars
	order by varnum;
quit;

/*---------------------------------------------------------------------------------------------------------------------------------------------*/
/* Write All Vars to log */
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
%put &amp;amp;orderedvars;
%put ---;
%put &amp;amp;reportvars;

/*---------------------------------------------------------------------------------------------------------------------------------------------*/
/* CREATE Proc SQL */
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
data za;
	length m_line $ 4096;
	m_line="proc sql noprint;";output;
	m_line=cats('09'x,"create table tbl_name as");output;
	m_line=cats('09'x,"select");output;
run;
data zb (keep=m_: sof);
	set vars end=sof;
	length m_line $ 4096 m_format $ 64 m_sof $ 1;
	if sof then m_sof='';else m_sof=',';
	if strip(format)='' then m_format='';else m_format=("format="||strip(format));

	m_line = cat('09'x,'09'x,strip(name)," ",repeat('09'x,3),"as ",strip(name)," ",repeat('09'x,2),strip(m_format)," ",'09'x,"label='",strip(label),"'",m_sof);
run;
data zc;
	length m_line $ 4096;
	m_line=cats('09'x,"from &amp;amp;lib..&amp;amp;memname");output;
	m_line=cats('09'x,"where 1=1");output;
	m_line=cats('09'x,";");output;
	m_line="quit;";output;
run;

data _null_ ;   
    set za zb zc ; 
    FILE  "&amp;amp;out_path.\proc_sql.txt"; 
    PUT  m_line ; 
run ;


/*---------------------------------------------------------------------------------------------------------------------------------------------*/
/* CREATE Proc SQL */
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
data zra;
	length m_line $ 4096;
	m_line=cat("proc report data=", "&amp;amp;memname", " nowd split='*';");output;
	m_line=cat(' ');output;
	m_line=cats('09'x,"column &amp;amp;reportvars ;");output;
run;

data zrb (keep=m_: sof);
	set vars end=sof;
	length m_line $ 4096 m_format $ 64 ;
	
	if strip(format)='' then m_format='';else m_format=("format="||strip(format));

	m_line = cat('09'x,"define ",strip(name)," ",repeat('09'x,2),"/ display ",strip(m_format)," ",'09'x,"'",strip(label),"';");
run;
data zrc;
	length m_line $ 4096;
	m_line=" ";output;
	m_line="run;";output;
run;

data _null_ ;   
    set zra zrb zrc ; 
    FILE  "&amp;amp;out_path.\proc_report.txt"; 
    PUT  m_line ; 
run ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 24 May 2020 09:46:06 GMT</pubDate>
    <dc:creator>Assaf_Attas</dc:creator>
    <dc:date>2020-05-24T09:46:06Z</dc:date>
    <item>
      <title>Generater_proc_SQL_and_REPORT</title>
      <link>https://communities.sas.com/t5/SAS-Users-Group-in-Israel/Generater-proc-SQL-and-REPORT/m-p/650148#M30</link>
      <description>&lt;P&gt;קטע הקוד הבא יהיה שימושי במיוחד לעצלנים כמוני &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;התכנית לוקחת טבלה מסוימת ומייצר ממנה בסיס קוד ניתן לעריכה עבור פרוצדורות SQL + REPORT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let lib 		=sashelp;
%let memname 	=class;
%let out_path 	=c:\temp;

/*---------------------------------------------------------------------------------------------------------------------------------------------*/
/* GET Dictionary */
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
proc sql;
	create table vars as
	select * /*varnum, name*/
	from dictionary.columns
	where libname=UPCASE("&amp;amp;lib") and memname = UPCASE("&amp;amp;memname")
	;
quit;

proc sql noprint;
	select distinct lowcase(name)
	into :orderedvars separated by ','
	from vars
	order by varnum;
quit;

proc sql noprint;
	select distinct lowcase(name)
	into :reportvars separated by ' '
	from vars
	order by varnum;
quit;

/*---------------------------------------------------------------------------------------------------------------------------------------------*/
/* Write All Vars to log */
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
%put &amp;amp;orderedvars;
%put ---;
%put &amp;amp;reportvars;

/*---------------------------------------------------------------------------------------------------------------------------------------------*/
/* CREATE Proc SQL */
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
data za;
	length m_line $ 4096;
	m_line="proc sql noprint;";output;
	m_line=cats('09'x,"create table tbl_name as");output;
	m_line=cats('09'x,"select");output;
run;
data zb (keep=m_: sof);
	set vars end=sof;
	length m_line $ 4096 m_format $ 64 m_sof $ 1;
	if sof then m_sof='';else m_sof=',';
	if strip(format)='' then m_format='';else m_format=("format="||strip(format));

	m_line = cat('09'x,'09'x,strip(name)," ",repeat('09'x,3),"as ",strip(name)," ",repeat('09'x,2),strip(m_format)," ",'09'x,"label='",strip(label),"'",m_sof);
run;
data zc;
	length m_line $ 4096;
	m_line=cats('09'x,"from &amp;amp;lib..&amp;amp;memname");output;
	m_line=cats('09'x,"where 1=1");output;
	m_line=cats('09'x,";");output;
	m_line="quit;";output;
run;

data _null_ ;   
    set za zb zc ; 
    FILE  "&amp;amp;out_path.\proc_sql.txt"; 
    PUT  m_line ; 
run ;


/*---------------------------------------------------------------------------------------------------------------------------------------------*/
/* CREATE Proc SQL */
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
data zra;
	length m_line $ 4096;
	m_line=cat("proc report data=", "&amp;amp;memname", " nowd split='*';");output;
	m_line=cat(' ');output;
	m_line=cats('09'x,"column &amp;amp;reportvars ;");output;
run;

data zrb (keep=m_: sof);
	set vars end=sof;
	length m_line $ 4096 m_format $ 64 ;
	
	if strip(format)='' then m_format='';else m_format=("format="||strip(format));

	m_line = cat('09'x,"define ",strip(name)," ",repeat('09'x,2),"/ display ",strip(m_format)," ",'09'x,"'",strip(label),"';");
run;
data zrc;
	length m_line $ 4096;
	m_line=" ";output;
	m_line="run;";output;
run;

data _null_ ;   
    set zra zrb zrc ; 
    FILE  "&amp;amp;out_path.\proc_report.txt"; 
    PUT  m_line ; 
run ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 May 2020 09:46:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Users-Group-in-Israel/Generater-proc-SQL-and-REPORT/m-p/650148#M30</guid>
      <dc:creator>Assaf_Attas</dc:creator>
      <dc:date>2020-05-24T09:46:06Z</dc:date>
    </item>
  </channel>
</rss>

