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

Hi everyone, is there an easy programmation way of 1) creating a new variable "NUTID", 2) then adding as many new lines to dataset as a previous variable "NUT" - how to go from left table in this attached excel to right end side table - PLEASE? 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

Here is one way to had a variable that takes on values of 1 to n of an existing variable.

 

data have;
   input a b;
datalines;
1 2
3 4
5 3
;
run;

data want;
   set have;
   do nutid = 1 to a;
      output;
   end;
run;
   

The key is the output. This will create a new record each time that the Output statement executes. All other varaibles in the data set will duplicate.

 

View solution in original post

3 REPLIES 3
Reeza
Super User

1. Create a list of the values needed in each column

2. Create the 'big dataset' which is empty using cross join in SQL

3. Merge in initial table to fill the values.

 

 

ballardw
Super User

Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

Here is one way to had a variable that takes on values of 1 to n of an existing variable.

 

data have;
   input a b;
datalines;
1 2
3 4
5 3
;
run;

data want;
   set have;
   do nutid = 1 to a;
      output;
   end;
run;
   

The key is the output. This will create a new record each time that the Output statement executes. All other varaibles in the data set will duplicate.

 

jackice
Calcite | Level 5

Thank you kindly speedy useful user ;-0) Exactly what I wanted - TKS and ill look at how to post with no excel file next time ;-0) 

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 755 views
  • 0 likes
  • 3 in conversation