<?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 Need a macro to loop through SharePoint surveys and create datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-a-macro-to-loop-through-SharePoint-surveys-and-create/m-p/406150#M98847</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I used this document to create a dataset from a SharePoint survey. (I am using SAS 9.4 on Windows 7 Professional 32-bit Operating System)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;A href="https://www.sas.com/content/dam/SAS/en_ca/User%20Group%20Presentations/Winnipeg-User-Group/HarryDroogendyk-SharepointListData-Fall2012.pdf" target="_blank"&gt;https://www.sas.com/content/dam/SAS/en_ca/User%20Group%20Presentations/Winnipeg-User-Group/HarryDroogendyk-SharepointListData-Fall2012.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I have 28 surveys that I need to create datasets from. Right now I have this code for each of the 28 surveys.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Start creating the datasets	*/
	%let dir = T:\FolderName\SubfolderName;

/* 1. Individual Application	*/

	%let xmlfile1 = ha_data1.xml;
	filename listout1 "&amp;amp;dir\&amp;amp;xmlfile1";

	proc http
	out = listout1
	url="&amp;amp;url?Cmd=Display&amp;amp;List=&amp;amp;ListID1&amp;amp;View=&amp;amp;ViewID1&amp;amp;XMLDATA=TRUE"
	method = "get"
	;
	run;

	filename HAabsent "&amp;amp;dir\&amp;amp;xmlfile1";
	filename sxlemap "&amp;amp;dir\HA1.map";
	libname HAabsent xmlv2 xmlmap=sxlemap
	access=readonly;

	/* Create the dataset */
	data sp_list_data01;
	set HAabsent.row ;
	run;
	quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have created a table with the Form_number (Survey number), Form_name (Survey name), ListID, ViewID (for the surveys).&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;So this is how those variables fit into the code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	/*1. the name of the xml data for the form*/
		%let xmlfile(Form_number) = ha_data(Form_number).xml;
		filename listout(Form_number) "&amp;amp;dir\&amp;amp;xmlfile(Form_number)";

	/*2. run the proc http for the form (issue the HTTP request to the web service)*/
		proc http
		out = listout(Form_number)
		url="&amp;amp;url?Cmd=Display&amp;amp;List=&amp;amp;(ListID)&amp;amp;View=&amp;amp;(ViewID)&amp;amp;XMLDATA=TRUE"
		method = "get"
		;
		run;

	/*3. use a previously created map to create an xml for each form*/
		filename HAabsent "&amp;amp;dir\&amp;amp;xmlfile(Form_number)";
		filename sxlemap "&amp;amp;dir\HA(Form_number.map";
		libname HAabsent xmlv2 xmlmap=sxlemap
		access=readonly;

	/*4. create the dataset*/
		data sp_list_data(Form_number);
		set HAabsent.row ;
		run;
		quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm sorry I can't provide test sharepoint survey data - it's on a secure site. Here is the macro I have so far but I realize it doesn't reference my table where the ListID and ViewID data resides:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro survey(num);
	%do i = 1 %to &amp;amp;num;
		proc http
		out = listout&amp;amp;i
		url="&amp;amp;url?Cmd=Display&amp;amp;List=&amp;amp;ListID&amp;amp;View=&amp;amp;ViewID&amp;amp;XMLDATA=TRUE"
		METHOD = "get"
		;
		run;
	%end;
%mend;

%survey(28);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Links, suggestions, even partial would be a huge help. I've learned so much from the people who have posted here, I'm so appreciative.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Kathy&lt;/P&gt;</description>
    <pubDate>Fri, 20 Oct 2017 20:45:06 GMT</pubDate>
    <dc:creator>kmusa</dc:creator>
    <dc:date>2017-10-20T20:45:06Z</dc:date>
    <item>
      <title>Need a macro to loop through SharePoint surveys and create datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-a-macro-to-loop-through-SharePoint-surveys-and-create/m-p/406150#M98847</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I used this document to create a dataset from a SharePoint survey. (I am using SAS 9.4 on Windows 7 Professional 32-bit Operating System)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;A href="https://www.sas.com/content/dam/SAS/en_ca/User%20Group%20Presentations/Winnipeg-User-Group/HarryDroogendyk-SharepointListData-Fall2012.pdf" target="_blank"&gt;https://www.sas.com/content/dam/SAS/en_ca/User%20Group%20Presentations/Winnipeg-User-Group/HarryDroogendyk-SharepointListData-Fall2012.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I have 28 surveys that I need to create datasets from. Right now I have this code for each of the 28 surveys.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Start creating the datasets	*/
	%let dir = T:\FolderName\SubfolderName;

/* 1. Individual Application	*/

	%let xmlfile1 = ha_data1.xml;
	filename listout1 "&amp;amp;dir\&amp;amp;xmlfile1";

	proc http
	out = listout1
	url="&amp;amp;url?Cmd=Display&amp;amp;List=&amp;amp;ListID1&amp;amp;View=&amp;amp;ViewID1&amp;amp;XMLDATA=TRUE"
	method = "get"
	;
	run;

	filename HAabsent "&amp;amp;dir\&amp;amp;xmlfile1";
	filename sxlemap "&amp;amp;dir\HA1.map";
	libname HAabsent xmlv2 xmlmap=sxlemap
	access=readonly;

	/* Create the dataset */
	data sp_list_data01;
	set HAabsent.row ;
	run;
	quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have created a table with the Form_number (Survey number), Form_name (Survey name), ListID, ViewID (for the surveys).&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;So this is how those variables fit into the code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	/*1. the name of the xml data for the form*/
		%let xmlfile(Form_number) = ha_data(Form_number).xml;
		filename listout(Form_number) "&amp;amp;dir\&amp;amp;xmlfile(Form_number)";

	/*2. run the proc http for the form (issue the HTTP request to the web service)*/
		proc http
		out = listout(Form_number)
		url="&amp;amp;url?Cmd=Display&amp;amp;List=&amp;amp;(ListID)&amp;amp;View=&amp;amp;(ViewID)&amp;amp;XMLDATA=TRUE"
		method = "get"
		;
		run;

	/*3. use a previously created map to create an xml for each form*/
		filename HAabsent "&amp;amp;dir\&amp;amp;xmlfile(Form_number)";
		filename sxlemap "&amp;amp;dir\HA(Form_number.map";
		libname HAabsent xmlv2 xmlmap=sxlemap
		access=readonly;

	/*4. create the dataset*/
		data sp_list_data(Form_number);
		set HAabsent.row ;
		run;
		quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm sorry I can't provide test sharepoint survey data - it's on a secure site. Here is the macro I have so far but I realize it doesn't reference my table where the ListID and ViewID data resides:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro survey(num);
	%do i = 1 %to &amp;amp;num;
		proc http
		out = listout&amp;amp;i
		url="&amp;amp;url?Cmd=Display&amp;amp;List=&amp;amp;ListID&amp;amp;View=&amp;amp;ViewID&amp;amp;XMLDATA=TRUE"
		METHOD = "get"
		;
		run;
	%end;
%mend;

%survey(28);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Links, suggestions, even partial would be a huge help. I've learned so much from the people who have posted here, I'm so appreciative.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Kathy&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 20:45:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-a-macro-to-loop-through-SharePoint-surveys-and-create/m-p/406150#M98847</guid>
      <dc:creator>kmusa</dc:creator>
      <dc:date>2017-10-20T20:45:06Z</dc:date>
    </item>
    <item>
      <title>Re: Need a macro to loop through SharePoint surveys and create datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-a-macro-to-loop-through-SharePoint-surveys-and-create/m-p/406163#M98850</link>
      <description>&lt;P&gt;If you have all of the information in a data set (recommended)&amp;nbsp;you could use the variables in the data set to build the strings to submit with call execute statements. The process is similar to creating&amp;nbsp;a macro in determining which is boiler plate and which pieces need to change. Then building the strings to submit for the changing bits.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suppose I had two parameters used to indicate part of dataset name and a variable and wanted to generate a bunch of (pretty trivial) data steps similar to&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data outname(suffix)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set start(suffix);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; rename &amp;lt;variable&amp;gt; = Constantname;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;if my data set has two variables: suffix and variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data _null_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set mydata; /* has the control informat*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; oname = cats('outname',suffix);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; inname= cats('start',suffix);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; call execute('data '||oname||';');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; call execute('set '||inname||';');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; call execute( 'Rename '||variable||'= Constantname; run;');&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;Call execute stacks up code lines that execute AFTER the data _null_ set completes. It isn't required that a single Call Execute call is a complete instruction and notice that the run; statement was included as part of the line with Rename.&lt;/P&gt;
&lt;P&gt;This will allow having all of the data step string manipulation functions to combine values and since URL seems to contain &amp;amp;instructions then placing them in single quotes for combining with other text seems like a way to head of some headaches.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 21:34:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-a-macro-to-loop-through-SharePoint-surveys-and-create/m-p/406163#M98850</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-20T21:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: Need a macro to loop through SharePoint surveys and create datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-a-macro-to-loop-through-SharePoint-surveys-and-create/m-p/406623#M99024</link>
      <description>&lt;P&gt;Thank you for your response. I think this may be the way to go. I'm having trouble creating my strings in my proc http statements.&lt;/P&gt;&lt;P&gt;I added a field "listout" to my table that has the resulting location and name of the desired XML file. I also added a field "url" to the table with the url of my SharePoint surveys.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	set Listid_viewid;
	call execute('proc http out = '||listout||'
				 url="'||url||'?Cmd=Display&amp;amp;List=&amp;amp;'||ListID||'&amp;amp;View=&amp;amp;'||ViewID||'&amp;amp;XMLDATA=TRUE"
				 METHOD = "GET"; RUN;');
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When I run this I get Error 22-322 Syntax error for each of the surveys&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc http out = T:\Folder\Subfolder\ha_data28.xml&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;P&gt;22&lt;/P&gt;&lt;P&gt;76&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: ;, AUTH_ANY, AUTH_BASIC, AUTH_NEGOTIATE, AUTH_NONE,&lt;/P&gt;&lt;P&gt;AUTH_NTLM, CLEAR_CACHE, CLEAR_CONN_CACHE, CLEAR_COOKIES, CT, EXPECT_100_CONTINUE, FOLLOWLOC, HEADERIN,&lt;/P&gt;&lt;P&gt;HEADEROUT, HEADEROUT_OVERWRITE, HTTP_TOKENAUTH, IN, METHOD, NOFOLLOW, NOFOLLOWLOC, NO_CONN_CACHE,&lt;/P&gt;&lt;P&gt;NO_COOKIES, OUT, PROXYHOST, PROXYPASSWORD, PROXYPORT, PROXYUSERNAME, PROXY_AUTH_BASIC,&lt;/P&gt;&lt;P&gt;PROXY_AUTH_NEGOTIATE, PROXY_AUTH_NONE, PROXY_AUTH_NTLM, URL, VERBOSE, WEBAUTHDOMAIN, WEBPASSWORD,&lt;/P&gt;&lt;P&gt;WEBUSERNAME.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 16:30:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-a-macro-to-loop-through-SharePoint-surveys-and-create/m-p/406623#M99024</guid>
      <dc:creator>kmusa</dc:creator>
      <dc:date>2017-10-23T16:30:11Z</dc:date>
    </item>
    <item>
      <title>Re: Need a macro to loop through SharePoint surveys and create datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-a-macro-to-loop-through-SharePoint-surveys-and-create/m-p/407047#M99160</link>
      <description>&lt;P&gt;I finally got this to work using your suggestion. Here it is - thanks so much!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	set Listid_viewid;
	ha_data=cats('ha_data',Form_number,'.xml');
	HA=cats('HA',Form_number,'.map');
	sp_list_data=cats('sp_list_data',Form_number);
	call execute('%Let xmlfile = '||ha_data||';');
	call execute('filename listout "&amp;amp;dir\&amp;amp;xmlfile";');
	call execute('proc http out = listout
				 url="&amp;amp;url?Cmd=Display&amp;amp;List='||ListID||'&amp;amp;View='||ViewID||'&amp;amp;XMLDATA=TRUE"
				 METHOD = "GET"; RUN;');
	call execute('filename HAabsent "&amp;amp;dir\&amp;amp;xmlfile";');
	call execute('filename sxlemap "&amp;amp;dir\'||HA||'";');
	call execute('libname HAabsent xmlv2 xmlmap=sxlemap access=readonly;');
	call execute('data '||sp_list_data||';');
	call execute('set HAabsent.row;');
	call execute('run;');
	call execute('quit;');
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Oct 2017 19:46:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-a-macro-to-loop-through-SharePoint-surveys-and-create/m-p/407047#M99160</guid>
      <dc:creator>kmusa</dc:creator>
      <dc:date>2017-10-24T19:46:27Z</dc:date>
    </item>
    <item>
      <title>Re: Need a macro to loop through SharePoint surveys and create datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-a-macro-to-loop-through-SharePoint-surveys-and-create/m-p/407464#M99302</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/158201"&gt;@kmusa&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I finally got this to work using your suggestion. Here it is - thanks so much!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	set Listid_viewid;
	ha_data=cats('ha_data',Form_number,'.xml');
	HA=cats('HA',Form_number,'.map');
	sp_list_data=cats('sp_list_data',Form_number);
	call execute('%Let xmlfile = '||ha_data||';');
	call execute('filename listout "&amp;amp;dir\&amp;amp;xmlfile";');
	call execute('proc http out = listout
				 url="&amp;amp;url?Cmd=Display&amp;amp;List='||ListID||'&amp;amp;View='||ViewID||'&amp;amp;XMLDATA=TRUE"
				 METHOD = "GET"; RUN;');
	call execute('filename HAabsent "&amp;amp;dir\&amp;amp;xmlfile";');
	call execute('filename sxlemap "&amp;amp;dir\'||HA||'";');
	call execute('libname HAabsent xmlv2 xmlmap=sxlemap access=readonly;');
	call execute('data '||sp_list_data||';');
	call execute('set HAabsent.row;');
	call execute('run;');
	call execute('quit;');
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Good!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I quite often have a long string variable that I can use the various the SAS string functions to build and then use&lt;/P&gt;
&lt;P&gt;Call execute(string);&lt;/P&gt;
&lt;P&gt;That way I can&amp;nbsp; use a Put statement to check the resolution of the functions before actually having the call execute statement execute.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 20:35:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-a-macro-to-loop-through-SharePoint-surveys-and-create/m-p/407464#M99302</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-25T20:35:14Z</dc:date>
    </item>
  </channel>
</rss>

