Hello All,
Good day!
Can anyone help me on this, i have Data Set on SAS Dataflux Data Management studio, where i have done the clustering, now base on each cluster i needs to have one .txt output file for each cluster.
Thanks
Dheeraj
Hi,
I think you can use Expression Language to do this, using the Grouping functionality.
This requires records to be sorted on the Cluster ID first.
file output string filepath //change the filepath to the place where you want to save your files filepath = "C:\"&`Cluster ID Field Name`&".txt" //this opens the file in Write mode output.open(filepath, "w")
output.close()
output.writeline(`My Field 1`)
This will create as many files as Cluster ID you have, as you can see in my example screenshot below:
Hope this helps.
Audrey
Does this post help? Split the data in Dataflux - SAS Support Communities
No Exactly helping me, i have data for example i have 100 System Data in one file, now i want to have 100 files for each one system.
Hi,
I think you can use Expression Language to do this, using the Grouping functionality.
This requires records to be sorted on the Cluster ID first.
file output string filepath //change the filepath to the place where you want to save your files filepath = "C:\"&`Cluster ID Field Name`&".txt" //this opens the file in Write mode output.open(filepath, "w")
output.close()
output.writeline(`My Field 1`)
This will create as many files as Cluster ID you have, as you can see in my example screenshot below:
Hope this helps.
Audrey
Hello Audrey,
Good day!
it worked for me, made some changes now i have this error. file not opened. at once it create one file that is blank.
could you please suggest. where i am going wrong.
Hi again,
Can you show me the code you currently have?
Seems like the file was not opened. Do you have a output.open line in the Pre-Expression?
Do you have write permissions in this folder?
Thanks,
Audrey
Hola,
Really appreciate for your reply, yes i do have permission and other access.
The output.close() shouldn't be in the Pre-grouping Expression. What happens here is you open the file AND close it before writting any line to it.
Try to move the output.close() to the Post-Grouping Expression code box and let me know how it goes.
Thanks,
Audrey
Hello Audrey,
it worked successfully without error, but output is not as desired. there is just one .txt file with limited data.
I am very new to this tool. sorry for the silly questions
Thanks once again
Dheeraj Lamba
The fact that you have only 1 file is because you put a static name to the file in your code: "Cluster1.txt".
If you look at my original code example, I was using a reference to the field name:
filepath = "C:\"&`Cluster ID Field Name`&".txt"
This will allow the engine to create one file for each Cluster ID value.
It contains limited data, because it's opening the same file for each cluster, flushing it and writing the new lines.
Once you fixed the first problem mentioned above, it should be creating multiple files with the appropriate data.
If you don't feel comfortable, you can send me your job, I'll take a look and make the changes.
Thanks,
Audrey
Awesome !! you are great Audrey!! i have all the files as per how many cluster i have :-
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.