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

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 

1 ACCEPTED SOLUTION

Accepted Solutions
audrey
SAS Employee

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.

 

  1. Add an Expression node to your job
  2. In the Grouping tab, select your cluster ID field in the "Group By" box at the top. The Expression node will now group your records by Cluster ID.
  3. In the Pre-group Expression tab (=the actions that will happen before a new cluster ID group), you'll have to create a reference to the file and open it:
    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")
  4. In the Post-group Expression, you will close the file:
    output.close()
  5. In the Expression code itself, you'll write the lines to the file that was opened for this Cluster ID group:
    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:

 

audrey_0-1655901103909.png

 

Hope this helps.

 

Audrey

 

www.sas.comsupport.sas.com
SAS®... THE POWER TO KNOW®

View solution in original post

12 REPLIES 12
lambad
Obsidian | Level 7

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.

audrey
SAS Employee

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.

 

  1. Add an Expression node to your job
  2. In the Grouping tab, select your cluster ID field in the "Group By" box at the top. The Expression node will now group your records by Cluster ID.
  3. In the Pre-group Expression tab (=the actions that will happen before a new cluster ID group), you'll have to create a reference to the file and open it:
    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")
  4. In the Post-group Expression, you will close the file:
    output.close()
  5. In the Expression code itself, you'll write the lines to the file that was opened for this Cluster ID group:
    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:

 

audrey_0-1655901103909.png

 

Hope this helps.

 

Audrey

 

www.sas.comsupport.sas.com
SAS®... THE POWER TO KNOW®
lambad
Obsidian | Level 7

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.

 

 

lambad_0-1655910778461.png

 

audrey
SAS Employee

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

www.sas.comsupport.sas.com
SAS®... THE POWER TO KNOW®
lambad
Obsidian | Level 7

Hola,

 

Really appreciate for your reply, yes i do have permission and other access.  

 

 

lambad_0-1655953186650.png

 

audrey
SAS Employee

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

www.sas.comsupport.sas.com
SAS®... THE POWER TO KNOW®
lambad
Obsidian | Level 7

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

 

lambad_0-1655968051882.png

 

Thanks once again

 

Dheeraj Lamba

 

audrey
SAS Employee

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

www.sas.comsupport.sas.com
SAS®... THE POWER TO KNOW®
lambad
Obsidian | Level 7

Awesome !! you are great Audrey!! i have all the files as per how many cluster i have :-

 

lambad_0-1655971015109.png

 

RacheLGomez123
Fluorite | Level 6
Step are given below-

Select and upload your TXT document for splitting.
Specify desired page numbers and click Split Now button.
Once your TXT document is splitted click on Download Now button.
Use Email button to send download link over email.

Regards,
Rachel Gomez

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to connect to databases in SAS Viya

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.

Discussion stats
  • 12 replies
  • 1320 views
  • 5 likes
  • 4 in conversation