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

@Reeza and @Tom  i made this from loud thinking:

 

Thanks A ton for your help and suggestions to build the code.

 

 

this works fine and takes very short time for execution.

%macro city;
proc sql noprint;
select count (distinct city) into :cdnt from WORK.DAC_3;
select distinct city into :city_1 - :city_%left(&cdnt.)
from WORK.DAC_3;
quit;

%let cnt = &cdnt;
%put &cnt &cdnt;
%do I = 1 %to &cnt;

proc export data= WORK.DAC_3 (where=(city = "&&CITY_&I"))
outfile= "\\10.4.1.205\Upload\DAC_&&CITY_&I"
dbms=xlsx 
replace;
%end;
%mend;

%city;

Tom
Super User Tom
Super User

@anirudhs wrote:
yes i tried it .... but the excel with city names excel is exporting the whole dataset not the data pertaining to the city only.

If you are trying the CALL EXECUTE() method then compare the code that you generated to what worked when you ran one example.

You should see the code in the SAS log with plus sign between the line numbers and the lines of code.

anirudhs
Obsidian | Level 7

@Reeza :

Your macro code also is giving error, mentioned 

 

NOTE: PROCEDURE EXPORT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

WARNING: Apparent symbolic reference WORK not resolved.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: Line generated by the CALL EXECUTE routine.
90 + proc export data=&WORK.DAC_3 (where=(city="ZIRAKPUR")) outfile="\\10.4.1.205\Upload\DAC_FINAL_ZIRAKPUR.xlsx" dbms=xlsx
_
22
76
90 !+replace; run;;
ERROR 22-322: Expecting a name.

ERROR 76-322: Syntax error, statement will be ignored.

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 32 replies
  • 12455 views
  • 10 likes
  • 4 in conversation