BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ss171
Calcite | Level 5

Hi , I need to export multiple tables into one text file 

%macro dist(ind);
proc export data=IBS_count_&ind. (firstobs=1 obs=10)
outfile='/risk/sbs/si/users/recon/crm_3.txt' dbms=tab;
putnames=yes;
run;
  %mend;
%dist(CRM_E1);%dist(CRM_E2);%dist(CRM_E3);%dist(CRM_E4);%dist(CRM_E5);%dist(CRM_E6);

When I run the code I just got 1 table . attached output as well . Can you please help in modifying the code . Also how can I align the count variable with its values 

ss171_0-1608109744001.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Second one first: TAB spacing is very dependent upon the file viewer. Generally the tab will show text at the nearest multiple of some number of characters. If the text in the first column is short one time the tab for the next column appears more to the left, when the text is longer then more to the right. In some cases you may not see any space at all because the first column of text was just the "wrong" length.

I am going to guess that the tab setting of the viewer you used is every 8 characters. Since the first row value of "DATE_E1" is 7 characters long then the "Count" starts in the 9th position as the first available after 8. The following rows have values that are 8 characters. I suspect if you count over you will find the count values start in column 16 or 17 depending.

 

Now, by multiple sets into a single file do you mean that as each file is added there should be a space or headers or something to indicate the start of the new data? Then Proc Export is not your tool as it is not designed to do that.

If you mean seamlessly see columns of data then append all of the data sets together first then export the large file.

 

Or manually create such a text file and show us what the result should be.

View solution in original post

2 REPLIES 2
ballardw
Super User

Second one first: TAB spacing is very dependent upon the file viewer. Generally the tab will show text at the nearest multiple of some number of characters. If the text in the first column is short one time the tab for the next column appears more to the left, when the text is longer then more to the right. In some cases you may not see any space at all because the first column of text was just the "wrong" length.

I am going to guess that the tab setting of the viewer you used is every 8 characters. Since the first row value of "DATE_E1" is 7 characters long then the "Count" starts in the 9th position as the first available after 8. The following rows have values that are 8 characters. I suspect if you count over you will find the count values start in column 16 or 17 depending.

 

Now, by multiple sets into a single file do you mean that as each file is added there should be a space or headers or something to indicate the start of the new data? Then Proc Export is not your tool as it is not designed to do that.

If you mean seamlessly see columns of data then append all of the data sets together first then export the large file.

 

Or manually create such a text file and show us what the result should be.

ss171
Calcite | Level 5

I have created sample dataset and the required format output . I want one .txt file which should have all distributions horizontally . Is there a way to do that 
data test;
input date1 date2 date3;
cards;
20201012 20201013 20201014
20201012 20201013 20201014
20201012 20201013 20201014
20171012 20171013 20171014
20201012 20201013 20201014
20171012 20171013 20171014
20171012 20171013 20171014
20171012 20171013 20171014
20171012 20171013 20171014
;
run;
%macro dist(ind);
proc sql;
create table count_&ind. as
select &ind., count (*) as COUNT
from test
group by &ind.
order by 2 desc ;
quit;
%mend;
%dist(date1);%dist(date2);%dist(date3);

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 511 views
  • 0 likes
  • 2 in conversation