Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4573834
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:50:26+00:00 2026-05-21T19:50:26+00:00

I have currently a dataset which contains the variables I need together with the

  • 0

I have currently a dataset which contains the variables I need together with the needed formats.

Now I am using the getvarc() function (among others) in a loop to get those variables to write to a file.
The first problem occuring ofcourse, is that some variables are not char type but num type. I could use getvarn() to retrieve those, but then the format goes to waste which I really need.

E.g. date in num type: 18750. Format = yymmdd10. Thus looking like 2011-05-03

Using the value=getvarn() for this field, it would retrieve 18750 for value. If I then want to output (using PUT) this value, it would not give me the 2011-05-03 date as I want.

So now I am looking for a better way to do this.
My first option is to use the sashelp.vcolumn data set, to retrieve the format on this field, and use it in the put statement to output in the right format.
My second option is to convert the data set containing this field (in reality it is about multiple data sets), where I convert all num type fields to char types remaining the right format.

Which option should I go with?
And in case of the second option, can this be done in a generic way (as I said, this is not about one variable only) ?

EDIT:

After the answer of Cmjohn I got to find a way to fix my problem. Not using the sashelp.vcolumn but using the varfmt function.
So a short explanation of what I am doing in my code:

  data _null_
  set dataset1;
  file file1;
  if somefield = x then do;
    dsid = open(datasetfield, i);
    rc = fetchobs (dsid);
    varnum = varnum(dsid,anotherfield);
    **varfmt = varfmt(dsid,anotherfield);
    if vartype(dsid,anotherfield) = 'N' then do;**
      value = getvarn(dsid,varnum);
      **value_formatted = putn(value,varfmt);**
    **end;
    else do;**
      value = getvarc(dsid,varnum);
      **value_formatted = putc(value,varfmt);
    end;**
    put value_formatted;
  end;
  run;

So this is in general (quickly out of my head) what I am doing now. The bold part of the solution is what I came up with after Cmjohns response. So my first question is answered, ‘How to do it?’.

But my added question: What would be most efficient in the long run: keep this process or make my data sets the way that all data can be read in by only using getvarc without the need of the type-check and the getfmt()?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T19:50:27+00:00Added an answer on May 21, 2026 at 7:50 pm

    I’d suggest that you use the vvalue function, or any of the other techniques provided in the answers to this question to put formatted values to a file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a single DataSet declared which contains 3 tables. For sake of
I have currently a dataset in asp which contains my members details. I am
I have a DataSet which contains two tables, Publication and Owner, which are linked
I currently have a dataset which has two columns that I'd like to compare.
I have a very large dataset which I am currently writing out to a
I have the following method which returns dataset. I am using .NET 2.0 DataSet
I am currently using Doctrine's DBAL library for MySQL interfacing and have currently built
I have four classes which share some arrangement of four properties. I have currently
I currently have 4 textboxes which will be used to store an ip address.
I have a VB.NET application which needs to generate reports (invoices) which contains optional

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.