I'm at the start of learning/using SAS so I'm hoping this is easy.. I just can't find any solutions, certainly not simple enough for me to understand at this stage!
I'm looking to pass the file names(full path) to a Macro I've already got working.
I can get the file names into a dataset, but is there a way to pass these names into the Macro so that it runs it for each file one at a time? Looking to 'process' each csv in a folder into the Macro individually.
My code is pretty simple:
Info I want to pass to the Macro-
Data fName;
Run;
(A single column of 10 filepaths for example)
The Macro I want to 'push' these to is-
%processFiles(FileToProcess= '//example/test/file01.csv')
The simple data set works, the Macro works.. just can't figure out how to 'trigger' it for each file in that dataset.
Hopefully it's something easy.
Thanks
Tried several approaches; loops, passing as a list, nesting macros, etc.
Use the dataset to generate the calls to the macro.
So if the dataset is named FILES and variable with the file name is called FNAME then you just need to run this data step to call the macro once for each file in the dataset.
data _null_;
set files ;
call execute('%nrstr(%processFiles)(FileToProcess='||quote(trim(fname),"'")||')');
run;
Related
I have a very simple code and I cannot figure out why it isn't working. Consider the dataframes below,
test1 = pd.DataFrame({'A':[1,2],'B':[3,4]})
test2 = test1+3
I would like to export these into two separate sheets in an excel spreadsheet so I wrote the code
with pd.ExcelWriter(path+'.xlsx',mode='W') as writer:
test1.to_excel(writer,sheet_name='Sheet1')
with pd.ExcelWriter(path+'.xlsx',mode='A') as writer:
test2.to_excel(writer,sheet_name='Sheet2')
where the path is just a string to the folder. Running this returns a single spreadsheet labeled 'Sheet2' and has the data from table2. Evidently it overwrote it and didn't append it. Why? How can I solve this?
Of course I can write
with pd.ExcelWriter(path+'.xlsx',mode='W') as writer:
test1.to_excel(writer,sheet_name='Sheet1')
test2.to_excel(writer,sheet_name='Sheet2')
which will generate a spreadsheet with both sheet1 and sheet2 and the data stored properly, but I would like to get this append to work because I am trying to generalize to many more dataframes.
I have a huge text file with lots of numbers divided into different sections and I want to extract only certain values. It is something like this
step 1
787268 4.29430E-01
787269 4.05248E-01
787270 3.99742E-01
787271 3.99136E-01
787272 3.98422E-01
787273 3.97019E-01
787274 3.95237E-01
step 2
787268 4.29430E-01
787269 4.05248E-01
787270 3.99742E-01
787271 3.99136E-01
787272 3.98422E-01
787273 3.97019E-01
787274 3.95237E-01
I want to copy into my excel file only the two columns in the step 2 section.
So I need a VBA code that allows me to search for a particular string and after it finds it copy and paste all the raws until the next step.
Any pieces of code?
Thanks
Stefano
You can use this website to help you find what you need, a simple Google search can go a long way.
I would suggest using an if found section to find the spot where you need to copy over.
Ex.
If (Range("A1").Value = "YOUR TEXT HERE") Then
'''' COPY OVER DATA
End If
I have some codes in kdb+(which uses q) which generates data in tabular form. The problem is I need to run each line separately and export the data to excel. Is there any way to automate this such that all the excel files can ben generated in one go?
Thanks
Whils't you can of course use csv as suggested above, .h.edsn is the function used for creating excel workbooks. It takes a dictionary of sheetNames->tables.
`:/var/tmp/excel.xls 0: .h.edsn `tab1`tab2!(([]10?10);([]20?20))
Then just open the xls file in excel.
I really could use some help
I have two .txt/csv files that I need to read from into my excel file.
In my excel file I have a whole column, each cell containing string of characters and I need to write a script to be able find matches and and copy an adjacent column from that txt file.
An example of a single row on my txt file is shown below:
"AB101AA","AB10 1AA","AB101A","AB10 1A","AB101","AB10 1","AB10","AB10","AB","10",394251,806376,,
"AB101AF","AB10 1AF","ABERDEEN","ABERDEENSHIRE",,"ABERDEEN, CITY OF"
My excel file would have a cell which probably say "AB101AF" and i want the corresponding cell to run through a million rows and find the match and then find the corresponding nth cell on the txt file and return it on the excel spreadsheet example "ABERDEEN, CITY OF".
I know I havent been helpful in explaining the issue. But any help would be appreciated.
Thank you
Depending upon the size of your text file you could import the file using the GetExternalData option in Excel. This would allow you to load your data into a different Sheet and then use a lookup to your data from the main Sheet. Using Match and/or vlookup should help here.
You could also add a workbook connection to the text file and search using the connection.
I have an Excel sheet that I created. For this sheet it pulls in a data feed on two of the sheets. The data feed has a parameter which I populate from a Drop Down that is fed off of another sheet. I'm trying to automate this process. I want to be able to have the file run through each one of the ID's (the parameter), run the data feed, save the excel sheet, run the next ID save and so on until it goes through the list. Can someone please please help me with this? I'm new to VBA.
1) you need a list of your IDs. I like Named Ranges, so mine is named ID_List
2) Loop thru your list
dim r as range
for each r in [ID_List]
'do yer stuff here
'what needs to be done with the value **r.value**???
'how do you want to save the file each time???
next
Need some specific answers!